1
I’m trying to figure out which field is a DateField
and thereby assign a class='date'
. How do I know the guy from the field?
The following code does not work but presents the logic:
class MeuForm(forms.ModelForm):
...
def __init__(self, *args, **kwargs):
super(MeuForm, self).__init__(*args, **kwargs)
for field_name, field in self.fields.items():
if field == "DateField": # (exemplo) como saber que é um DateField?
field.widget.attrs['class'] = 'date'
self.fields['DateField'].widget.attrs['class'] = 'date'
would not work in this case?– stderr
@Qmechanic73 that way I would have to assign
'date'
for each field, the way I asked I assign at once to all type FieldsDateField
.– Paulo