Reputation: 3475
I was wondering if someone could explain to me why my verbose_name attribute of a model fields is being lost when using the follow code;
Model
:
information_request_issued_date = models.DateField(verbose_name='Date Information Request Issued', null=True, blank=True)
Form
class:
class InformationRequestForm(forms.ModelForm):
class Meta:
model = DevelopmentAssessment
fields = ('information_request_issued_date')
def __init__(self, *args, **kwargs):
super(InformationRequestForm, self).__init__(*args, **kwargs)
self.fields['information_request_issued_date'] = forms.DateField(('%d/%m/%Y',), widget=forms.DateTimeInput(format='%d/%m/%Y', attrs={'class': 'date'}))
If i don't have the self.fields
declaration in the form class the verbose_name
works fine.
Any ideas?
Upvotes: 1
Views: 304
Reputation: 7858
Maybe because it's now a regular form field and thus doesn't have an attribute named verbose_name
. Instead, it now has a label
attribute.
Try this:
self.fields['information_request_issued_date'].label = 'Date Information Request Issued'
Upvotes: 2