Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19886 closed Bug (duplicate)

documentation: FormWizard.as_view() does not have the attribute get_form()

Reported by: gandalf013@… Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation for form wizards has this example:

>>> from myapp.forms import ContactForm1, ContactForm2
>>> from myapp.views import ContactWizard
>>> initial = {
...     '0': {'subject': 'Hello', 'sender': 'user@example.com'},
...     '1': {'message': 'Hi there!'}
... }
>>> wiz = ContactWizard.as_view([ContactForm1, ContactForm2], initial_dict=initial)
>>> form1 = wiz.get_form('0')
>>> form2 = wiz.get_form('1')
>>> form1.initial
{'sender': 'user@example.com', 'subject': 'Hello'}
>>> form2.initial
{'message': 'Hi there!'}

The above example (with the definitions of ContactForm1, ContactForm2, and ContactWizard from earlier) fails:

AttributeError: 'function' object has no attribute 'get_form'

It seems like the example assumes that as_view() should return an instance of ContactWizard, whereas it actually returns a function.

Change History (2)

comment:1 by Carl Meyer, 12 years ago

Resolution: duplicate
Status: newclosed

Thanks for the report! This is a duplicate of #19880.

comment:2 by Tim Graham, 12 years ago

You can't initialize ContactWizard directly with a list of forms and the initial dict. The as_view call is correct, but then you need to pass request to the function that's returned. Maybe RequestFactory could be used for the example, but a session is also needed on the request so it seems a bit complicated to have this example use the shell.

Note: See TracTickets for help on using tickets.
Back to Top