fusionbox / django-betterforms

Making forms suck less
https://django-betterforms.readthedocs.org/
BSD 2-Clause "Simplified" License
135 stars 54 forks source link

Using MultiForm with Formset #51

Open quapka opened 7 years ago

quapka commented 7 years ago

I have a following setup:

SessionWizardView
  |_MultiForm (Step 1)
      |_forms.Form
      |_forms.ModelForm
      |_forms.BaseFormSet
  |_ Step 2
  ...

It sort of works, but I had to do one tweak on the forms.BaseFormSet:

@forms.BaseFormSet.cleaned_data.setter                                        
def cleaned_data(self, value):                                                
    # this setter is needed, because MultiForm sets cleaned_data during       
    # vallidation and it's not defined on BaseFormSet by default in Django 1.8
    for i, data in enumerate(value):                                          
        self.forms[i].cleaned_data = data                                     

because MultiForm sets the cleaned_data during its own cleaning.

The other issue I'm having is during tests. When I use

response = self.client.get(reverse(<SessionWizardView>))

then it's quite a digging, to get all the form data (management_form of the BaseFormSet). Would it be possible to make using BaseFormSet with MultiForm easier? I haven't checked the code, so I don't know myself, what would be needed.