Django 修复 Admin 复数 [英] Django fix Admin plural

查看:19
本文介绍了Django 修复 Admin 复数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在新的 dev django 版本的管理站点上将某些模型名称从Categorys"更改为Categories"?在旧版本中(没有管理站点和管理模型)你可以这样做;http://www.the-dig.com/博客/帖子/customize-plural-name-django-admin/

How do I change some models name from "Categorys" to "Categories" on admin site in the new dev django version? In the old version (whithout admin sites and admin models) you could just do this; http://www.the-dig.com/blog/post/customize-plural-name-django-admin/

但是 - 现在在我的基于 modeladmin 的类中设置 verbose_name_plural 什么都不做.有人遇到同样的问题吗?

However - now setting verbose_name_plural inside my modeladmin based class does nothing. Anyone encouter the same issue?

推荐答案

好吧,看起来 Meta 类方法仍然有效.所以在你的模型中放置一个元类仍然可以解决问题:

Well well, it seems like the Meta class approach still works. So placing a meta class inside your model will still do the trick:

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

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

Note that we use the lower case here, as django is smart enough to capitalize it when we need it.

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

I find setting this option in model-class weird as opposed to the admin.py file. Here is the location in the dev docs where it is described:
http://docs.djangoproject.com/en/dev/ref/models/options/#verbose-name-plural

这篇关于Django 修复 Admin 复数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆