Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

verbose_name vs verbose_name_plural (Django)

I created "Category" model with "verbose_name" and "verbose_name_plural" following some tutorial and the documentation of verbose_name and verbose_name_plural:

# "store/models.py"

from django.db import models

class Category(models.Model):
    name = models.CharField(max_length=100)
    
    class Meta:
        verbose_name = "category"
        verbose_name_plural = "categories"

Then, the plural model name "Categories" is displayed in Django Admin as shown below:

enter image description here

Now, I wanted to display the singular model name "Category" but when I removed "verbose_name_plural" as shown below:

# "store/models.py"

from django.db import models

class Category(models.Model):
    name = models.CharField(max_length=100)
    
    class Meta:
        verbose_name = "category"
        # verbose_name_plural = "categories"

"Categorys" was displayed instead of "Category" in Django Admin as shown below:

enter image description here

Now, my questions are:

  • How to display the singular model name "Category" in Django Admin properly?
  • What is the difference between "verbose_name" and "verbose_name_plural"?
  • How to use "verbose_name" and "verbose_name_plural" properly?
like image 396
Kai - Kazuya Ito Avatar asked Oct 28 '25 23:10

Kai - Kazuya Ito


1 Answers

If you don't explicitly set the attribute verbose_name_plural on a Model, Django adds 's' to the name of the model when displaying the name in the admin.

So, in your case, if you want the title text in the admin to be displayed same as your model name, set:

class Category(models.Model):
    ...
    class Meta:
         verbose_name = 'category'
         verbose_name_plural = 'Category'

Link to the Django Codebase.

Although, I would personally prefer the plural term on the title.

like image 149
Abhyudai Avatar answered Oct 30 '25 13:10

Abhyudai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!