Home > Enterprise >  Change DjangoMPTT admin model name
Change DjangoMPTT admin model name

Time:07-20

I have the following MPTTModel and admin.py:

class Category(MPTTModel):
    name = models.CharField(max_length=50, unique=True)
    parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children')

    def __str__(self):
        return self.name

    class MPTTMeta:
        order_insertion_by = ['name']

admin.site.register(infoModels.Category)

When I am at the admin page the model appears as "Categorys", how can I change that to be "Categories"?

CodePudding user response:

That's just your usual Model.Meta.verbose_name_plural.

class Category(MPTTModel):
    # ...
    class Meta: 
        verbose_name = 'category'
        verbose_name_plural = 'categories'

Be sure to not use capitalization in there (unless there's e.g. an acronym that needs to be capitalized (e.g. FTP servers)); Django will take care of that for you.

  • Related