djangodjango-modelsdjango-admin

Django admin shows models name with extra "s" at the end


I'm new to Django. In the admin panel, the name of the models has an extra "s" at the end. How can I fix that?

enter image description here


Solution

  • Why is django-admin adding an 's'

    There is a naming convention in Django the models are named in the singular. So your classes should be named:

    class Comment(models.Model):
       ...
    
    class Note(models.Model):
       ...
    

    An instance of such a class represents a single comment, not a set of comments. Likewise consider the following

    # doesn't really make sense
    Comments.objects.get(...)
    
    # reads much better
    Comment.objects.get(...) #e.g. get from the comment objects
    

    This is so much of a convention that Django admin expects for your classes to be named in the singular. For this reason, Django adds on an 's' as a standard way of pluralising your class names. (This will admittedly not work for all words and is very anglo-centric, but as an override, Django provides the verbose_name_plural meta-attribute).

    How to fix it:

    Rename your classes so they are in the singular. This will make your code a lot more readable to anyone who is used to reading django. It will also make your models named in a way consistent with other third-party packages. If your class names are not in English, or do not pluralise simply by appending an s, use verbose_name_plural e.g:

    Class Cactus(models.Model):
        class Meta:  
            verbose_name_plural = 'Cacti'