开发者

django1.3 + django-formwizard + initial datas issue

i am using django 1.3, with django-formwizard. I have a WizardView with 2 ModelForms which works fine in creation mode (as_view linked in the url conf) but i can't make it work in edit mode. When i do in a view:

return MyWizard.as_view([Form1,Form2], instance_dict={0:instance1, 1:instance2})(request)

the wizard instance is not present in the context if i do:

return MyWizard([Form1,Form2], instance_dict={0:instance1, 1:instance2})

i get: init() takes exactly 1 non-keyword argument (2 given)

MyWizard is very basic, it onl开发者_JAVA技巧y has get_template_names and done methods.


It appears the FormWizard constructor accepts a keyword argument named initial and nothing else, which is a dictionary mapping step to an initial data dict.

def __init__(self, form_list, initial=None):

https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/#providing-initial-data-for-the-forms

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜