3

用户提交表格一。

表格 1 用作表格 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--

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

如果有人知道这些新的表单向导,你介意给我一次。我确定这很简单...

4

2 回答 2

4

对于旧 Django 版本,有一个 Django 1.4 向导的反向移植:

https://github.com/stephrdev/django-formwizard

您应该使用它而不是 1.4 中已弃用的 Django 1.3 向导。你移植到 Django 1.4 会更容易。

如果您愿意,可以像这样准备移植到 Django 1.4:

try:
    # Django 1.4
    from django.contrib.formtools.wizard.views import SessionWizardView
except ImportError:
    # For older django version use formwizard backport
    from formwizard.views import SessionWizardView
于 2011-12-22T10:51:07.457 回答
2

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.

于 2011-10-19T14:34:40.630 回答