80
I had a quick read of https://docs.djangoproject.com/en/1.4/ref/forms/widgets/
which rabbited on about widgets – apparently they are
Django’s representation of a HTML input element. The widget handles the rendering of the HTML
and then each form field is tied to a widget – have a read of:
https://docs.djangoproject.com/en/1.4/ref/forms/fields/#built-in-fields
for the ChoiceField, the defaultWidget is “Select” (as noted in the above link). Ok, knowing the right widget, to add the class i just needed:
widget=forms.Select(attrs={'class':'regDropDown'})
so that my final line ended up reading:
gender = ChoiceField(label='', choices=SEX, widget=forms.Select(attrs={'class':'regDropDown'}))
Huzzah!
8
the ChoiceField use the forms.Select widget
forms.Select(attrs={"name": "select_0","class": "form-control"})
- [Django]-'WSGIRequest' object has no attribute 'user' Django admin
- [Django]-How can I allow django admin to set a field to NULL?
- [Django]-Django query get last n records
Source:stackexchange.com