I want to set choices in dynamic.
I used __set_choices method but, when request method is POST, is_valid method always return False.
if request.method=='POST': _form = MyForm(request.POST) if _form.is_valid(): #something to do
I often set the choices dynamicly in the constructor:
class MyForm(BaseForm):
afield = forms.ChoiceField(choices=INITIAL_CHOICES)
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['afield'].choices = my_computed_choices
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With