Skip steps on a django FormWizard

django, formwizard, python

Solution

The hook method process_step() gives you exactly that opportunity. After the form is validated you can modify the self.form_list variable, and delete the forms you don't need.

Needles to say if you logic is very complicated, you are better served creating separate views for each step/form, and forgoing the FormWizard altogether.

Problem

I have an application where there is a FormWizard with 5 steps, one of them should only appear when some conditions are satisfied. The form is for a payment wizard on a on-line cart, one of the steps should only show when there are promotions available for piking one, but when there are no promotions i want to skip that step instead of showing an empty list of promotions. So I want to have 2 possible flows: ``` step1 - step2 - step3 step1 - step3 ```

Original source