Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How model class "Name" becomes plural "Names" under Admin Page?

In Django's tutorial, a models.py class is created named "Question" (singular). It is also registered to be included within the Admin Page using admin.site.register(Question) (singular)

But then under the Admin Page, it's listed as "Questions" (plural)

Is Django automatically renaming things under the Admin Page to be grammatically satisfying?

Django's Tutorial.. add "Question" to Admin Page

link to png of Admin Page

like image 855
user12711 Avatar asked Mar 08 '23 22:03

user12711


1 Answers

In the model definition of the Question you can control this by declaring the Meta class:

class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    class Meta(object):
        verbose_name_plural = 'Questions'

You can find this here in the docs

As explained in the docs, 'If this isn’t given, Django will use verbose_name + "s".'

like image 129
Dan Moica Avatar answered Mar 24 '23 05:03

Dan Moica