本文介绍了在DB中保存Django的formwizard form_list最简单的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从一个模型创建了多个子表单,以在Django中使用FormWizard。



令人困惑的是保存部分。一旦用户完成表单,我想将信息保存在数据库中。这是相当简单的一种形式,我可以在这里说

然后通过每个窗体?但是后来我需要知道我在哪一种形式找到正确的领域。没有更简单的方法吗?



感谢您的建议!

解决方案

尝试以下方式:

  instance = MyModel()
for form in form_list:
的字段,在form.cleaned_data.iteritems()中的值:
setattr(实例,字段,值)
instance.save()
/ pre>

I have created multiple sub-forms from one model to use the FormWizard in Django.

Confusing is the saving part. Once the user finished the form, I wanted to save the information in the DB. This is fairly simply with one form, where I can say

But could I do it when I get a form_list returned. I read some postings but they did not make any sense to me.

Can I clean the data

and then go through every form? But then I would need to know in which form I am to find the right fields. Isn´t there any easier way to do it?

Thank you for your advice!

解决方案

Try something like this:

instance = MyModel()
for form in form_list:
    for field, value in form.cleaned_data.iteritems():
        setattr(instance, field, value)
instance.save()

这篇关于在DB中保存Django的formwizard form_list最简单的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:06