I have several ModelFormused to build surveys whose models contain many questions (> 30 each). Multiple-choice questions are currently presented as an element <select>, but to improve UX, I would like to change this to switches.
Like ModelForm, I rely on django to automatically create fields on the form. Therefore, although I know that you can change each field in a form by doing this:
class SurveyForm(ModelForm):
...
field_one = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect())
these definitions do not currently exist, and I will need to create at least 150 such definitions. I'm sure there is a better way to override widget selection (perhaps a ModelForm extension?). Or, alternatively, can I do this by attaching a widget to a field definition?
I looked through the documents and the source of Django, but I can not find where the widget is selected for the model fields with choiceskwarg.
source
share