I am trying to use a MultipleChoiceField
with a ModelForm but am obviously implementing it wrong.
There are two linked? issues:
- The question only submits of the user selects nothing
- The question displays the default option "------" which i want to remove
- If I remove the "-----" by removing
blank=True
the question will not submit at all, see image below.
- If I remove the "-----" by removing
If anyone can tell me what I am going wrong it would be greatly appriciated.
modles.py
ELECTIONS = (
('NONE', 'None'),
('LOCAL', 'Local elections'),
('STATE', 'State elections e.g. Governorship'),
('NATIONAL', 'National elections e.g. Congress and Senate'),
('PRESIDENTIAL', 'Presidential elections'),
('OTHER', 'Other'),
('DONT_KNOW', "Don't know"),
)
elections = models.CharField(null=True, max_length=100, blank=True, default=None, choices = ELECTIONS, verbose_name = 'Which elections do you regularly vote in or intend to vote in? Select all that apply.')
forms.py
class SurveyFormD(forms.ModelForm): # Political Viewpoints
class Meta:
model = Person
fields = ['liberal_conservative', 'democrat_republican', 'voting_rights', 'elections']
widgets = {'liberal_conservative' : forms.RadioSelect,
'democrat_republican' : forms.RadioSelect,
'voting_rights' : forms.RadioSelect,
'elections' : forms.CheckboxSelectMultiple,}