Using dynamic Choice Field in Django Using dynamic Choice Field in Django django django

Using dynamic Choice Field in Django


You can populate them dynamically by overriding the init, basically the code will look like:

class NewForm(forms.Form):    def __init__(self, choices, *args, **kwargs):        super(NewForm, self).__init__(*args, **kwargs)        self.fields["choices"] = forms.ChoiceField(choices=choices)

NewForm(my_actual_choices) or NewForm(my_actual_choices, request.POST, request.FILES) etc.