Django Admin:如何覆盖模型verbose_name?

时间:2013-10-28 15:31:32

标签: django django-admin

我有两个模型(国家和州),我只为国家制作了一个带有TabularInline的ModelAdmin。

class StateInline(admin.TabularInline):
    model = State

class CountryAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['name']}),
    ]
    inlines = [StateInline]

admin.site.register(Country, CountryAdmin)

如何覆盖Country模型的verbose_name Meta属性?我想将菜单中的表单重命名为“Countries / States”,而不仅仅是“Countries”?

1 个答案:

答案 0 :(得分:11)

使用Meta

在您的模型中:

from django.utils.tranlation import gettext_lazy as _

class Country(models.Model):
    # your fields
    class Meta:
        verbose_name = _("Country / State")
        verbose_name_plural = _("Countries / States")