samedi 21 mars 2015

Django: Set choices on form attribute MultipleChoiceField

I have the following django form:



class SpecifyColumnsForm(forms.Form):
columns = forms.MultipleChoiceField(required=False,
widget=forms.CheckboxSelectMultiple)


Now, I want to specify the choices for this MultipleChoiceField from views.py. How can I do that?


I have tried the following, but it did not work:



columns_form = SpecifyColumnsForm(request.POST)
columns_form.choices = (('somestuff', 'spam'),
('otherstuff', 'eggs'),
('banana', 'bar'))


Thanks!


Aucun commentaire:

Enregistrer un commentaire