I can dynamically invoke a single form associated with the data that I selected using the ealier step .
But when I am in the done method, I see that my form_list remains unchanged.
here is what i did:
def get_form_list(request, form_list=None): if form_list is None: form_list = [ProviderForm, DummyForm, ConsummerForm, DummyForm, \ ServicesDescriptionForm] return UserServiceWizard.as_view(form_list=form_list)(request) class UserServiceWizard(SessionWizardView): instance = None def __init__(self, **kwargs): self.form_list = kwargs.pop('form_list') return super(UserServiceWizard, self).__init__(**kwargs) def get_form_instance(self, step): if self.instance is None: self.instance = UserService() return self.instance def get_context_data(self, form, **kwargs): data = self.get_cleaned_data_for_step(self.get_prev_step( self.steps.current)) if self.steps.current == '1': service_name = str(data['provider']).split('Service')[1] form = class_for_name('th_' + service_name.lower() + '.forms', service_name + 'ProviderForm') self.form_list['1'] = form
in step 0, my form_list is fine:
{u'0': <class 'django_th.forms.wizard.ProviderForm'>, u'1': <class 'django_th.forms.wizard.DummyForm'>, u'2': <class 'django_th.forms.wizard.ConsummerForm'>, u'3': <class 'django_th.forms.wizard.DummyForm'>, u'4': <class 'django_th.forms.base.ServicesDescriptionForm'>}
in step 1, my form_list is fine: we can see that the second form is my expected
{u'0': <class 'django_th.forms.wizard.ProviderForm'>, u'1': <class 'th_rss.forms.RssProviderForm'>, u'2': <class 'django_th.forms.wizard.ConsummerForm'>, u'3': <class 'django_th.forms.wizard.DummyForm'>, u'4': <class 'django_th.forms.base.ServicesDescriptionForm'>}
in step 2, my form_list is ko; same as step 0: my second form returns a DummyForm
{u'0': <class 'django_th.forms.wizard.ProviderForm'>, u'1': <class 'django_th.forms.wizard.DummyForm'>, u'2': <class 'django_th.forms.wizard.ConsummerForm'>, u'3': <class 'django_th.forms.wizard.DummyForm'>, u'4': <class 'django_th.forms.base.ServicesDescriptionForm'>}
How can I do to change self.form_list and save the changes I made in get_context_data to the end of the wizard, and not at every step?
EDIT here is the complete code that works great with Rohan's suggestion:
def get_form(self, step=None, data=None, files=None): """ change the form instance dynamically from the data we entered at the previous step """ if step is None: step = self.steps.current if step == '1':