我可以在Django的单个表单中使用多个表单集吗?如果可以,如何? [英] Can I use multiple number of formset in a single form in django,if yes how?

查看:96
本文介绍了我可以在Django的单个表单中使用多个表单集吗?如果可以,如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须制作一种使用了多个表单集的表单.请告诉我是否可行.如果是,那怎么办?

I have to make a form in which more than one formset is used. please tell me if this is possible. if yes then how?

推荐答案

您可以在表单中添加尽可能多的表单集.只需在视图中创建/初始化它们,然后将其传递到模板即可在表单中呈现.

You can add as many formsets in the form. Just create/init them in view and pass to template to render in the form.

类似的东西:

{{ formset1.management_form }}
{% for form in formset1 %}
    {{ form }}
{% endfor %}

{{ formset2.management_form }}
{% for form in formset2 %}
    {{ form }}
{% endfor %}

您在一个视图中使用多个表单集,您需要使用表单前缀,如此处在视图中使用多个表单集 简而言之:

You are using multiple formsets in one view, you need to use prefix for the forms as explained here Using more than one formset in a view In short:

article_formset = ArticleFormSet(prefix='articles')
book_formset = BookFormSet(prefix='books')

这篇关于我可以在Django的单个表单中使用多个表单集吗?如果可以,如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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