假设我有一个继承自SuperFoo的模型Foo:
class SuperFoo(models.Model): name = models.CharField('name of SuperFoo instance', max_length=50) ... class Foo(SuperFoo): ... # do something that changes verbose_name of name field of SuperFoo
在Foo类中,我想重写SuperFoo的name字段的verbose_name。我可以吗?如果不是,最好的选择是在模型表单定义内设置标签以使其显示在模板中吗?
我使用的一个简单的技巧是:
class SuperFoo(models.Model): name = models.CharField('name of SuperFoo instance', max_length=50) ... class Meta: abstract = True class Foo(SuperFoo): ... # do something that changes verbose_name of name field of SuperFoo Foo._meta.get_field('name').verbose_name = 'Whatever'