Django修复管理员复数

时间:2010-04-06 19:35:36

标签: django django-admin

如何在新版dev django版本的管理网站上将某些模型名称从“分类”更改为“类别”? 在旧版本中(没有管理站点和管理模型)你可以这样做; http://www.the-dig.com/blog/post/customize-plural-name-django-admin/

然而 - 现在在我的基于modeladmin的类中设置verbose_name_plural什么都不做。 有人问同样的问题吗?

2 个答案:

答案 0 :(得分:215)

好吧,似乎Meta类方法仍然有效。 因此,在模型中放置元类仍然可以解决问题:

class Category(models.Model):
    class Meta:
        verbose_name_plural = "categories"

请注意,我们在这里使用小写字母,因为django足够聪明,可以在需要时将其大写。

我发现在模型类中设置此选项很奇怪而不是admin.py文件。 以下是开发文档中描述的位置:
http://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name-plural

答案 1 :(得分:0)

为此,您需要为模型添加元类

class Category(models.Model):
    --- model field here ---
    class Meta: 
        verbose_name = "Category"
        verbose_name_plural = "Categories"

apps.py中模型管理员的奖励

class CategoryConfig(AppConfig):
    name = "Category"
    verbose_name = "Categories"