Home > Software engineering >  verbose name on class field in django
verbose name on class field in django

Time:08-14

I am need of help to add a verbose name.

class Address(models.Model) :
    
    class Zip(models.Field):
       def db_type(self, connection):
           return 'char(8)'

    zip            = Zip()
    address        = models.CharField(max_length=200, verbose_name="Rua")

        .....

Need put the verbose name of ZIP to CEP.

CodePudding user response:

Django models.Field.__init__() takes verbose_name as parameter you can set name there

class Address(models.Model):

    class Zip(models.Field):

        def __init__(self, *args, **kwargs):
            kwargs['verbose_name'] = "Zip code"
            super().__init__(*args, **kwargs)

        def db_type(self, connection):
            return 'char(8)'

    zip = Zip()
    address = models.CharField(max_length=200, verbose_name="Rua")
  • Related