I have created multiple sub-forms from one model to use the FormWizard in Django.
Confusing is the saving part. Once the user finished the form, I wanted to save the information in the DB. This is fairly simply with one form, where I can say
one_form_from_model.sa开发者_如何学Pythonve()
But could I do it when I get a form_list returned. I read some postings but they did not make any sense to me.
Can I clean the data
form.cleaned_data for form in form_list]
and then go through every form? But then I would need to know in which form I am to find the right fields. Isn´t there any easier way to do it?
Thank you for your advice!
Try something like this:
instance = MyModel()
for form in form_list:
for field, value in form.cleaned_data.iteritems():
setattr(instance, field, value)
instance.save()
精彩评论