I have been struggling to create a django FormWizard
. I think that I am pretty close, but I cannot figure out how to save to the database.
I tried the solution suggeted here:
def done(self, form_list, **kwargs):
instance = MyModel()
for form in form_list:
for field, value in form.cleaned_data.iteritems():
setattr(instance, field, value)
instance.save()
return render_to_response('wizard-done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
but placing it in the done method results in a No Exception Supplied
error. Placing this code in the save
method, on the other hand, does not save the information.
I also tried the solution suggested here:
def done(self, form_list, **kwargs):
for form in form_list:
form.save()
return render_to_response('wizard-done.html', {
'form_data': [form.cleaned_data for form in form_list],
})
But this returns another error: AttributeError at /wizard/ 'StepOneForm' object has no attribute 'save'
. Have you faced this problem? How do I save information to the database after the wizard is submitted? Thanks
def done(self, form_list, **kwargs):
new = MyModel()
for form in form_list:
new = construct_instance(form, new, form._meta.fields, form._meta.exclude)
new.save()
return redirect('/')
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