I have 3 different forms like so:
class Questions(forms.ModelForm):
class Meta:
model = Client
fields = ['life_areas', 'life_desires', 'life_ambitions',]
class BasicContact(forms.ModelForm):
class Meta:
model = Client
fields = ['status', 'first_name', 'email_address', 'country',]
class PhoneContact(forms.ModelForm):
class Meta:
model = Client
fields = ['phone_number', 'best_time', 'preferences',]
I have created a form wizard that gathers information using these three forms.
FORMS = [("questions", Questions),
("basiccontact", BasicContact),
("phonecontact", PhoneContact),]
class ClientFormWizard(SessionWizardView):
form_list = FORMS
def done(self, form_list, form_dict, **kwargs):
# get data from the forms
questions = form_dict['questions']
basiccontact = form_dict['basiccontact']
phonecontact = form_dict['phonecontact']
formdata = dict(questions.items() + basiccontact.items() + phonecontact.items())
clientform = ClientForm(formdata)
new_client = clientform.save()
# return redirect(...)
I am basically trying to concatenate the information from the three forms into a single ClientForm and then save it. However, I am not sure how to concatenate information from the three forms. I tried doing it the dictionary way, but it didn't work. What is the best way to accomplish this sort of concatenation?
Aucun commentaire:
Enregistrer un commentaire