I'm using Django 1.4. I've spent quite a while googleing and looking at docs on the django page, https://docs.djangoproject.com/en/1.4/ref/contrib/formtools/form-wizard/ etc. Few people have asked the question and no-one happens to have answered it.
What I need to do is:
use the slug paramater from the urls.py (as follows):
FORMS=[...]
url(r'^url/(?P<slug>[\w-]+)/form/$', WizardWizard.as_view(FORMS)),
in the views.py (as follows):
class WizardWizard(SessionWizardView):
template_name = "template.html"
extra_context = Model.objects.filter(slug=slug) # HERE!
def done(self, form_list, **kwargs):
...
After being stuck for days the answer is fairly simple. If you're reading this, make sure you're using Class based generic views first or it's a different problem.
You can find the relevant information on the following link, it's not clear this is how you assign extra context (not with the extra_context var): https://docs.djangoproject.com/en/1.4/ref/contrib/formtools/form-wizard/#django.contrib.formtools.wizard.views.WizardView.get_context_data
example code (slightly different from theirs) that sets a context var for ALL of you formwizard pages:
def get_context_data(self, form, **kwargs):
context = super(PaperworkWizard, self).get_context_data(form=form, **kwargs)
#this line makes camp available as a var in the template context.
#it sets it to an OBJECT RETRIEVED USING THE SLUG FROM THE URL.
context.update({'camp': Camp.objects.get(slug=self.kwargs.get("slug"))})
return context
You need to put this code in the subclass you've made of the SessionWizardView (or CookieWizardView). In the context of the question, the WizardWizard class in the views.py file.
The problem with doing this any other way, is that the self.args and self.kwargs are set when the dispatch function is run. NOTE: You can't set the context by setting the extra_context variable This is where I fell down.
credit to nkryptic from the #django channel on freenode. It's a fantastic place to head if you are still stuck after this answer. I wish everyone the best of luck.