It will probably help if you read the contrib/formtools/wizard.py
code. It's fairly straightforward and following it will give you a better sense of what you need to do.
There is a process_step
hook in there which you'll need to override in your own form wizard. What I did is look at what step I was at do some special processing if the form validated (ie, it had cleaned_data
):
class MyFormWizard(FormWizard):
def process_step(self, request, form, step):
if step == 0 and hasattr(form, 'cleaned_data'):
# Do special stuff
If I understand your question correctly, you want the 2nd step to serve a particular form based on the user's choice from the 1st form. In that case, what I might try first is to build a dynamic generic form for the 2nd step, where the fields used are based on the results from the first form (untested):
def process_step(self, request, form, step):
if step == 0 and hasattr(form, 'cleaned_data'):
# The initial attribute is a dictionary which maps the step number
# to a dictionary of what should be initial values.
# You can use/abuse this in a form's constructor
self.initial[1] = {'fields': {'field1': field, 'field2': another}}
Then, in your 2nd form
class MySecondForm(forms.Form):
def __init__(self, *args, **kwargs):
super(StatBuilderForm2, self).__init__(*args, **kwargs)
for name, field in kwargs['initial']['fields'].iteritems():
self.fields[name] = field