如何根据先前的表单为表单添加信息?
用户提交表格一。
表单一用作表单 2 form_factory 的种子信息
在尝试哄骗库存 Django 1.3 使用表单工厂 3 小时后,使用 django 表单向导。
我正在尝试找出如何播种这些信息。我有信息 - 我只是不知道把它贴在哪里。 (哦,我有想法..)
--urls.py--
url(r'homes/bulk/$',
BulkHomeWizard.as_view([('home_0', BulkUploadFormOne),
('home_1', formset_factory(BulkUploadFormTwo, extra=1))])
--views.py--
class BulkHomeWizard(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super(BulkHomeWizard, self).get_context_data(form, **kwargs)
self.template_name = 'axis/bulk_%s.html' % self.steps.current
if self.steps.current == 'home_1':
data = self.get_cleaned_data_for_step('home_0')
# OK I have the data.. Now I thought I could simply pass the form back in....
HomeFormSet = formset_factory(BulkUploadFormTwo, extra=0)
form = HomeFormSet(initial=data['homes'])
context.update({'form': form})
return context
如果有人知道这些新表单向导,您介意给我看一遍吗?我确信这很简单...
User submits form one.
Form one is used as seed info for form 2 form_factory
Using django form wizard after 3 hours of attempting to coax the stock Django 1.3 to use a form factory.
I'm trying to figure out how to seed this information. I have the information - I just don't know where to stick it. (Oh I have ideas..)
--urls.py--
url(r'homes/bulk/
--views.py--
class BulkHomeWizard(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super(BulkHomeWizard, self).get_context_data(form, **kwargs)
self.template_name = 'axis/bulk_%s.html' % self.steps.current
if self.steps.current == 'home_1':
data = self.get_cleaned_data_for_step('home_0')
# OK I have the data.. Now I thought I could simply pass the form back in....
HomeFormSet = formset_factory(BulkUploadFormTwo, extra=0)
form = HomeFormSet(initial=data['homes'])
context.update({'form': form})
return context
If anyone knows these new form wizards would you mind giving me a once over. I'm sure it's simple...
,
BulkHomeWizard.as_view([('home_0', BulkUploadFormOne),
('home_1', formset_factory(BulkUploadFormTwo, extra=1))])
--views.py--
class BulkHomeWizard(SessionWizardView):
If anyone knows these new form wizards would you mind giving me a once over. I'm sure it's simple...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个针对旧版 Django 版本的 Django 1.4 向导的向后移植:
https://github.com/stephrdev/django- formwizard
您应该使用它来代替 Django 1.3 向导,后者在 1.4 中已弃用。您移植到 Django 1.4 将会更加容易。
如果您愿意,可以像这样准备 Django 1.4 的移植:
There is a backport of Django 1.4 wizards for older Django version:
https://github.com/stephrdev/django-formwizard
You should use this instead of Django 1.3 wizard which is deprecated in 1.4. Your port to Django 1.4 will be easier.
You can prepare your port to Django 1.4 like this if you want to:
关键是SessionWizardView...这是在Django的开发分支中,直到1.4才会发布。您当然可以下载开发分支并使用 SessionWizardView,但不建议将其用于生产代码!
1.3 版表单向导的旧版本记录在此处。它的作用要少得多(因此是新版本),并且基本上将所有内容都作为隐藏字段传递。
The key is SessionWizardView... This is in the development branch of Django and won't be released until 1.4. You can of course download the development branch and use the SessionWizardView but this isn't recommended for production code!
The older version of the forms wizard for 1.3 is documented here. It does much less (hence the new version) and basically passes everything around as hidden fields.