[Answered ]-Formset initial choice field

2👍

You are passing the instance of the form instead of the form class to the formset_factory method. You can set the choices after instantiating the formset.

forms.py:

class PO_Form(forms.Form):
    base_item = forms.ChoiceField(choices=(), required=True)
    color_or_print = forms.ChoiceField(choices=(), required=True)
    material = forms.ChoiceField(choices=(), required=True)
    size_group = forms.ChoiceField(choices=(), required=True)

views.py:

PO_FormSet = formset_factory(PO_Form)

formset = PO_FormSet()

for form in formset.forms:
    form.fields['base_item'].choices = baseItem_choices
    form.fields['color_or_print'].choices = color_choices
    form.fields['material'].choices = material_choices
    form.fields['size_group'].choices = sizeGroup_choices
👤Ivan

Leave a comment