I had it working fine using a single template, but then i wrote different html for different forms extending a common base html and while submitting the last form the wizard reloads the last form and does not execute done method.
Heres my url.py:
url(r'^settings/new/$', settings_view, name = 'new_settings'),
View:
FORMS = [
("Basic", BasicSettingsForm),
("Calculation", CalculationForm)
]
TEMPLATES = {
"Basic":"settings/basic-settings.html",
"Calculation":"settings/calculation_settings_form.html"
}
class WizardView(SessionWizardView):
def get_template_names(self):
return [TEMPLATES[self.steps.current]]
def get_form_instance(self, step):
return self.instance_dict.get(step, None)
def get_form(self, step=None, data=None, files=None):
form = super(WizardView, self).get_form(step, data, files)
return form
def done(self, form_list, **kwargs):
b_form = form_list[0]
c_form = form_list[1]
try:
b_data = b_form
b_data.save()
c_data = c_form
c_data.save()
message = ''
except Exception as e:
print e
message = "Could not save the settings"
return message_view(self.request, message = message)
@login_required
def attendance_settings_view(request):
attWizardView = WizardView.as_view(FORMS)
return attWizardView(request)
base.html
{% load i18n %}
<form id="myForm" action="" method="POST">{% csrf_token %}
{% block wizardform %}
{% endblock %}
{% if wizard.steps.prev %}
<button class="btn btn-small btn-primary" name="wizard_goto_step" type="submit"
value="{{ wizard.steps.prev }}">{% trans "Back" %}</button>
{% endif %}
{% if wizard.steps.current == wizard.steps.last %}
<input class="btn btn-small btn-primary" type="submit" value="{% trans " Finish " %}"/>
{% else %}
<input type="submit" value="{% trans " Next " %}" class="btn btn-small btn-primary">
{% endif %}
{{ wizard.management_form }}
</form>
{% endblock %}
These errors usually occur, if the form does not validate correctly. I usually include all fields and test it, before adapting the fields (e.g. hiding some fields).