how to override the verbose name of a superclass model field in django

后端 未结 5 1524
梦如初夏
梦如初夏 2020-12-05 02:35

Let\'s say that I have a model Foo that inherits from SuperFoo:

class SuperFoo(models.Model):
    name = models.CharField(\'name of SuperFoo instance\', max_         


        
5条回答
  •  北海茫月
    2020-12-05 02:57

    A simple hack I have used is:

    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'
    

提交回复
热议问题