Search code examples
djangodjango-1.4formwizard

How to Dynamically Repeat Steps in Django Formwizard 1.4?


I'm trying to repeat a step in Django Formwizard (Django 1.4) conditionally based on a checkbox in the step. The form creates an object, and has a checkbox (hopefully) allowing them to repeat the step and create another object of the same model with the same form.

I saw this answer: Django FormWizard Dynamically Alter form_list but unfortunately I think it only applies to older versions of the FormWizard.

The process_step function doesn't have a form_list attribute anymore. It also doesn't have a current step attribute (or step attribute) but I can access the current step through the QueryDict of the form. It contains a dictionary of forms, but I don't think inserting another step into that dictionary will do anything, and unfortunately since it's a dictionary not a list I'd have to modify every step key after where I insert it.

So, is there a good way to add new steps into the form list with Django 1.4 FormWizard?

Update -- beginning to think overriding get_next_step(self, step) might be the way to go, but any input is much appreciated.

Update #2 -- Tried working with get_next_step, but was unable to insert a new form into the instance's form_list. Doesn't mean it's not possible -- ideas?


Solution

  • Verdict is, it's impossible. I haven't quite figured out why it worked sometimes with the prior two solutions, but after digging into the code for the form wizard, it's clear that each request reinitializes the instance form-list (well, technically it's a new instance), and so even if you update the list as it stands in storage, or update it in get_form_list(), there are some calls that directly hit the instance variable rather than accessing it via get_form_list() and it would take some major refactoring to adjust that.

    I went another route for this project, but might try to put something together for this soon.