[英]Can I use multiple number of formset in a single form in django,if yes how?
I have to make a form in which more than one formset is used. 我必须制作一个使用多个formset的表单。 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.
只需在视图中创建/初始化它们并传递给模板以在表单中呈现。
Something like: 就像是:
{{ 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: 您在一个视图中使用多个formset,您需要为表单使用前缀,如此处所述在视图中使用多个formset简而言之:
article_formset = ArticleFormSet(prefix='articles')
book_formset = BookFormSet(prefix='books')
When adding a prefix='article' We need to consider that the id of the formset will change and there are other changes too like 添加前缀='文章'时我们需要考虑到formset的id会发生变化,还有其他变化
<label for="id_form-0-title">Title:</label>
<label for="id_article-0-title">Title:</label>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.