I want to incorporate a FormWizard to handle a long form. After researching, it seems that django-merlin is the best option since it manages the formwizard via sessions. Trying to incorporate it (as mentioned in the django wizard docs), however, results in an AttributeError: type object 'CreateWizard' has no attribute 'as_view'
.
Here is what it looks like:
from merlin.wizards.session import SessionWizard
class StepOneForm(forms.Form):
year = forms.ChoiceField(choices=YEAR_CHOICES)
...
class StepTwoForm(forms.Form):
main_image = forms.ImageField()
...
class StepThreeForm(forms.Form):
condition = forms.ChoiceField(choices=CONDITION)
...
class CreateWizard(SessionWizard):
def done(self, form_list, **kwargs):
return HttpResponseRedirect(reverse('wizard-done'))
url:
url(r'^wizard/(?P<slug>[A-Za-z0-9_-]+)/$', CreateWizard.as_view([StepOneForm, StepTwoForm, StepThreeForm])),
Since the merlin docs are a little sparse, I chose to use the as_view()
method as described in the original django form wizard docs, but it results in an AttributeError
. How should I incorporate the merlin wizard in my urlconf? Thanks for your ideas!
This is the error and traceback that I get after updating based on @mVChr's answer and defining steps like this:
step_one = Step('step_one', StepOneForm())
Error and Traceback:
TypeError at / issubclass() arg 1 must be a class
Traceback:
File /lib/python2.7/django/core/handlers/base.py" in get_response
89. response = middleware_method(request)
File "/lib/python2.7/django/utils/importlib.py" in import_module
35. __import__(name)
File "/myproject/myproject/urls.py" in <module>
7. from myapp.forms import step_one, step_two, step_three, CreateWizard
File "/myproject/myapp/forms.py" in <module>
16. step_one = Step('step_one', StepOneForm())
File "/lib/python2.7/merlin/wizards/utils.py" in __init__
36. if not issubclass(form, (forms.Form, forms.ModelForm,)):
Exception Type: TypeError at /
Exception Value: issubclass() arg 1 must be a class
Although Im still getting an error, I feel closer to the solution thanks to @mVChr. Any ideas on how to solve this error are greatly appreciated! Thanks for any ideas!