Django Formwizard 1.4中的动态重复步骤 [英] How to Dynamically Repeat Steps in Django Formwizard 1.4?

查看:120
本文介绍了Django Formwizard 1.4中的动态重复步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Django Formwizard(Django 1.4)中重复一步,有条件地基于步骤中的复选框。该表单创建一个对象,并且有一个复选框(希望)允许他们重复该步骤,并以相同的形式创建相同模型的另一个对象。



我看到这个答案: Django FormWizard动态更改form_list ,但不幸的是,我认为它只适用于较老的FormWizard的版本。



process_step函数不再有一个form_list属性。它还没有当前步骤属性(或步骤属性),但是我可以通过窗体的QueryDict访问当前步骤。它包含一个表单的字典,但我不认为在该字典中插入另一个步骤将会做任何事情,不幸的是,由于它是一个字典而不是一个列表,我必须在插入它之后修改每个步骤键。



所以,有没有一个很好的方法来添加新的步骤到表单列表与Django 1.4 FormWizard?



更新 - 开始认为覆盖get_next_step(self,step)可能是要走的路,但是任何输入都是非常感激的。



更新#2 - 尝试使用get_next_step,但是无法将新表单插入到实例的form_list中。不是意味着不可能 - 想法?

解决方案

裁决是,这是不可能的。我不太清楚为什么它有效地与之前的两个解决方案,但在挖掘表单向导的代码之后,很明显,每个请求都会重新初始化实例表单(在技术上这是一个新的实例),所以即使您更新列表,因为它在存储中,或更新在get_form_list()中,有一些调用直接命中实例变量,而不是通过get_form_list(),它需要一些重大的重构来调整。



我已经去了这个项目的另一条路线,但可能会尽快把东西放在一起。 p>

I'm trying to repeat a step in Django Formwizard (Django 1.4) conditionally based on a checkbox in the step. The form creates an object, and has a checkbox (hopefully) allowing them to repeat the step and create another object of the same model with the same form.

I saw this answer: Django FormWizard Dynamically Alter form_list but unfortunately I think it only applies to older versions of the FormWizard.

The process_step function doesn't have a form_list attribute anymore. It also doesn't have a current step attribute (or step attribute) but I can access the current step through the QueryDict of the form. It contains a dictionary of forms, but I don't think inserting another step into that dictionary will do anything, and unfortunately since it's a dictionary not a list I'd have to modify every step key after where I insert it.

So, is there a good way to add new steps into the form list with Django 1.4 FormWizard?

Update -- beginning to think overriding get_next_step(self, step) might be the way to go, but any input is much appreciated.

Update #2 -- Tried working with get_next_step, but was unable to insert a new form into the instance's form_list. Doesn't mean it's not possible -- ideas?

解决方案

Verdict is, it's impossible. I haven't quite figured out why it worked sometimes with the prior two solutions, but after digging into the code for the form wizard, it's clear that each request reinitializes the instance form-list (well, technically it's a new instance), and so even if you update the list as it stands in storage, or update it in get_form_list(), there are some calls that directly hit the instance variable rather than accessing it via get_form_list() and it would take some major refactoring to adjust that.

I went another route for this project, but might try to put something together for this soon.

这篇关于Django Formwizard 1.4中的动态重复步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆