问题描述
我已经设法使用modelformset_factory创建我需要的表单。
I have managed to create the forms I need using modelformset_factory.
avaluos = Avaluo.objects.filter(Estatus__contains='CONCLUIDO',Factura__isnull=True)
FacturaFormset = modelformset_factory(Avaluo,form=FacturaForm,extra=0)
目前,为每个找到的行生成以下HTML:
Currently this is generating the following HTML for each of the rows found:
<form id="id-FacturaForm" class="blueForms" method="post">[..]</form>
<form id="id-FacturaForm" class="blueForms" method="post">[..]</form>
<form id="id-FacturaForm" class="blueForms" method="post">[..]</form>
我想使用单个提交按钮提交所有表单。
I want to submit all the forms using a single submit button.
任何想法?
最后使用,这让我可以为每行输入输入,然后我只是手动添加表单和提交
I ended up using django-crispy-forms which allowed me to gerate inputs for each row, and then I just manually added the form and submit.
self.helper.form_tag = False
{{example_formset.management_form }}
{% for a,b in olist %}
{{ b.id }}
<tr>
<td style="width:10px;"> {% crispy b %} </td>
<td> {{a.id}} </td>
</tr>
{% endfor %}
推荐答案
进入。您不需要单独使用表单
标签,这是使用表单的全部。
Read more into model formsets. You don't need to have separate form
tags, it's the whole point of using a formset.
<form method="post" action="">
{{ factura_formset.management_form }}
<table>
{% for form in factura_formset %}
{{ form }}
{% endfor %}
</table>
</form>
此外,每次使用 id
在一个页面上多次定义属性...一个开发人员呼吁自己睡觉在世界某个地方。
Also, every time you use the id
attribute more than once on a page… a developer cries themselves to sleep somewhere in the world.
这篇关于如何在django中使用单个提交按钮提交多个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!