如何在新的 dev django 版本的管理站点上将某些模型名称从“Categorys”更改为“Categories”?在旧版本中(没有管理站点和管理模型)你可以这样做; http://www.the-dig.com/blog/post/customize-plural-name-django-admin/
但是 - 现在在我的基于模型管理的类中设置 verbose_name_plural 什么都不做。有人遇到同样的问题吗?
好吧,看起来 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
为此,您需要为模型添加元类
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"
不定期副业成功案例分享