Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- When using inline formsets with form wizards, where does formset form validation go?
- class Parent(models.Model):
- name = models.CharField(max_length=256)
- def __unicode__(self):
- return name
- class Child(models.Model):
- name = models.CharField(max_length=256)
- parent = models.ForeignKey(Parent)
- def __unicode__(self):
- return name
- test_forms = [['parent', ParentForm],['child', ChildFormSet]]
- urlpatterns = patterns('example.views',
- url(r'^$', TestWizard.as_view(test_forms)),
- )
- class ParentForm(ModelForm):
- class Meta:
- model = Parent
- class ChildForm(ModelForm):
- class Meta:
- model = Child
- exclude = ('parent',)
- ChildFormSet = inlineformset_factory(Parent, Child, extra=1)
- class TestWizard(SessionWizardView):
- """
- This WizardView is used to create multi-page forms and handles all the
- storage and validation stuff using sessions.
- """
- #template_name = ''
- # def get_template_names(self):
- # """
- # Returns a list of template names to be used for the request.
- # Overridden TemplateResponseMixin for specifying template for step.
- # """
- # return 'survey/forms/wizard_form.html'
- #
- # def get_context_data(self, form, **kwargs):
- # context = super(TestWizard, self).get_context_data(form=form, **kwargs)
- # return context
- #
- # def get_form_initial(self, step):
- # """
- # Returns dict (list of key, values) for initial form data.
- # Useful for populating form fields with data from prior form, with extra
- # logic for dealing with formsets.
- # """
- # return self.initial_dict.get(step, {})
- #
- # def get_form(self, step=None, data=None, files=None):
- # """
- # Constructs the form for a given step - overridden to add extra arguments
- # """
- # form = super(TestWizard, self).get_form(step, data, files)
- # return form
- def done(self, form_list, **kwargs):
- return render_to_response('survey/thanks.html', {
- 'form_data': [form.cleaned_data for form in form_list],
- })
- {% extends "base.html" %}
- {% load i18n %}
- {% block head %}
- {{ wizard.form.media }}
- {% endblock %}
- {% block content %}
- <p>DEFAULT WIZARD FORM Step {{ wizard.steps.step1 }} of {{ wizard.steps.count }}</p>
- <form action="" method="post">{% csrf_token %}
- <table>
- {{ wizard.management_form }}
- {% if wizard.form.forms %}
- {{ wizard.form.management_form }}
- {% for form in wizard.form.forms %}
- {{ form }}
- {% endfor %}
- {% else %}
- {{ wizard.form }}
- {% endif %}
- </table>
- {% if wizard.steps.prev %}
- <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">{% trans "first step" %}</button>
- <button name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "prev step" %}</button>
- {% endif %}
- <input type="submit" value="{% trans "submit" %}"/>
- </form>
- {% endblock %}
Add Comment
Please, Sign In to add comment