I cannot change the verbose_name of a field

Asked

Viewed 66 times

1

I am programming an agenda, and for that, I created the model "Commitment", which has the following code:

class Compromisso(models.Model):
    nome = models.CharField(max_length=100, verbose_name="Nome")
    descricao = models.TextField(verbose_name="Descrição")
    data_criacao = models.DateField(default=datetime.today, blank=True, verbose_name="Data de criação")
    prazo_cumprimento = models.DateField(DateInput)

Migrations have already been performed and changed, and the verbose_name that Django set as the default for the "prazo_cumprimento" field was django.forms.widgets.DateInput. When I make the argument verbose_name="Prazo de cumprimento" and I try to make the migration, that mistake happens:

TypeError: __init__() got multiple values for argument 'verbose_name'

How can I fix this?

1 answer

0


Quoting the documentation in free translation:

Each field, with the exception of Foreignkey, Manytomanyfield and Onetoonefield, receives an optional first argument - verbose name. If verbose name is not given, Django will automatically create it using the field name by converting underscores into spaces.

Just when you did:

prazo_cumprimento = models.DateField(DateInput, verbose_name="Prazo de cumprimento")

Django understood that you have already defined the verbose name as 'Dateinput' so he ended up creating the verbose name as django.forms.widgets.DateInput.

The right thing would be:

prazo_cumprimento = models.DateField('prazo_de_cumprimento')

There is a similar question in Soen

  • I understand, it is my first time dealing with dates in models and I ended up getting confused. Thank you very much!

  • It worked, here. Again, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.