diff --git a/docs/wizard.rst b/docs/wizard.rst index 78c5bbbe..a918b18a 100644 --- a/docs/wizard.rst +++ b/docs/wizard.rst @@ -376,6 +376,16 @@ Advanced ``WizardView`` methods def get_form_kwargs(self, step): return {} +.. method:: WizardView.get_form_class(step) + + Returns the form class which will be used when instantiating the form + instance on given ``step``. + + The default implementation:: + + def get_form_class(self, step): + return self.form_list[step] + .. method:: WizardView.get_form_instance(step) This method will be called only if a :class:`~django.forms.ModelForm` is diff --git a/formtools/wizard/views.py b/formtools/wizard/views.py index aeded43f..9e747b5b 100644 --- a/formtools/wizard/views.py +++ b/formtools/wizard/views.py @@ -216,7 +216,7 @@ def get_form_list(self): # call the value if needed, passes the current instance. condition = condition(self) if condition: - form_list[form_key] = form_class + form_list[form_key] = self.get_form_class(form_key) return form_list def dispatch(self, request, *args, **kwargs): @@ -394,6 +394,12 @@ def get_form_kwargs(self, step=None): """ return {} + def get_form_class(self, step): + """ + Returns the form class to use for the provided step. + """ + return self.form_list[step] + def get_form(self, step=None, data=None, files=None): """ Constructs the form for a given `step`. If no `step` is defined, the @@ -405,7 +411,7 @@ def get_form(self, step=None, data=None, files=None): """ if step is None: step = self.steps.current - form_class = self.form_list[step] + form_class = self.get_form_class(step) # prepare the kwargs for the form instance. kwargs = self.get_form_kwargs(step) kwargs.update({