I have a form wizard that contains 3 forms. Basically, what I am trying to do is to pass data from first and second forms to the third one. What I tried is to add a dictionary attribute to wizard class and update that dictionary every time the method process_step is called. Django 1.4 documentation says that this method is called every time a page is rendered for all submitted steps.
In the following sample code, dictionary attribute is changed with integer self.test to keep it simple. In this case, every time the method process_step is called, the value of self.test is 2, never increases. It seems that the method __init__ is called for each form.
class MyWizard(SessionWizardView):
def __init__(self, *args, **kwargs):
super(MyWizard, self).__init__(*args, **kwargs)
self.test = 1
def process_step(self, form):
self.test += 1
print self.test
return self.get_form_step_data(form)
Other than this solution, is there a more elegant way to pass data between forms of form wizard?
You can do it with sessions passing the “inital” info to the 3rd form.
Here’s an example of something similar.