2👍
✅
You can change the field choices overriding the form init method (so that it accepts a choice parameter) or you can change the field’s choices after the init, depending on your needs.
First Case would be like this:
class AnswersForm(forms.Form):
radioButton = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect())
def __init__(self, radio_choices= None, *args, **kwargs):
super(AnswersForm, self).__init__(self, *args, **kwargs)
if radio_choices is not None:
self.fields['radioButton'].choices = radio_choices
View example:
form_instance = AnswersForm(new_choices)
Source:stackexchange.com