Answer the question
In order to leave comments, you need to log in
How to pass a localized verbose_name from the model to the form?
I have a form with this field:
year_first = forms.DateField(label=Clone._meta.get_field('year_first').verbose_name.capitalize(),
input_formats=['%y', '%Y', '%d.%m.%Y', '%d-%m-%Y'], required=False,
widget = YearTextInput)
year_first = models.DateField(db_index=True, blank=True, null=True, verbose_name=_('year released'))
Answer the question
In order to leave comments, you need to log in
In general, if anyone is interested, it seems to be a Django bug described here
. In short, the capitalize () method is to blame, it is not supported by lazy objects. One solution, described on the page with a bug, another (similar) I found myself:
In the form class:
@lazy
def capit(string):
return string.capitalize()
year_first = forms.DateField(label=capit(Clone._meta.get_field('year_first').verbose_name),
input_formats=['%y', '%Y', '%d.%m.%Y', '%d-%m-%Y'], required=False,
widget = YearTextInput)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question