Hey,
I would like to use the same Form to multiple purposes and just change the options.
Here is my form :
class ChoiceEx(forms.Form):
choices = (("choice1", "c1"), ("choice2", "c2"))
field = forms.ChoiceField(choices=choices,
widget=forms.RadioSelect(attrs={'class': "questionnaire-radio"}))
Here is my view were I want to override choice1 and choice2 by choice3 and choice4
def exChoice(request):
choices = (("choice3", "c3"), ("choices4", "c4"))
form = ChoiceEx()
field = django.forms.ChoiceField(choices=choices,
widget=django.forms.RadioSelect(attrs={'class': "questionnaire-radio"}))
form.fields["field"] = field
print(form.fields["field"]._choices)
return render(request, 'predictions/exView.html', {"form": form})
I think I’m able to change the value of the form because the print displays :
[(‘choice3’, ‘c3’), (‘choices4’, ‘c4’)]
However, when I display my page it shows the previous form choices : choice1 and choice2
Why my form is changed to the previous value ? Is the form regenerated at one point ?
Thank you