'Problems placing formsets in wizard forms
I have a question regarding a multi form step wizard, in 3 steps I am using form sets that I have previously set up from the views and rendering it in the template. Now I see that when using the wizard you have to make some modifications to the view, it is something that does not know how to mix the view with the wizard and the formset. I already saw how it is used with simple forms but with formset I have not found tutorials that explain it. I imagine that when I make that change I also have to make adjustments to the template? Percent I was checking django-formtools-addons and django-multipleformwizard but I didn't understand the documentation
views.py
def create_Presupuestos(request):
extra_forms = 1
ParteFormSet = formset_factory(PresupuestosParteForm, extra=extra_forms, max_num=20)
ManoObraFormSet = formset_factory(PresupuestosManoObraForm, extra=extra_forms, max_num=20)
PagosFormSet = formset_factory(PresupuestosPagosForm, extra=extra_forms, max_num=20)
presupuestosclientesform=PresupuestosClientesForm(request.POST or None)
presupuestosvehiculosform=PresupuestosVehiculosForm(request.POST or None)
presupuestosparteform=PresupuestosParteForm(request.POST or None)
presupuestosmanoobraform=PresupuestosManoObraForm(request.POST or None)
presupuestospagosform=PresupuestosPagosForm(request.POST or None)
presupuestosfotosform=PresupuestosFotosForm(request.POST or None)
if request.method == 'POST':
formset = ParteFormSet(request.POST, request.FILES)
manoObra_formset = ManoObraFormSet(request.POST, request.FILES,prefix='manoobra')
pagos_formset = PagosFormSet(request.POST, request.FILES, prefix='pagos')
#formset = ParteFormSet(request.POST, request.FILES,prefix='__form')
if formset.is_valid() and manoObra_formset.is_valid() and pagos_formset.is_valid():
presupuestosclientesform.save()
return redirect('presupuestos:index')
else:
formset = ParteFormSet()
manoObra_formset = ManoObraFormSet(prefix='manoobra')
pagos_formset = PagosFormSet(prefix='pagos')
presupuestosfotosform = PresupuestosFotosForm(request.POST or None)
return render(request,'Presupuestos/new-customer.html',{
'presupuestosclientesform':presupuestosclientesform,
'presupuestosvehiculosform':presupuestosvehiculosform,
'presupuestosparteform':presupuestosparteform,
'presupuestosmanoobraform':presupuestosmanoobraform,
'presupuestospagosform':presupuestospagosform,
'presupuestosfotosform':presupuestosfotosform,
'formset':formset,
'manoObra_formset':manoObra_formset,
'pagos_formset':pagos_formset
})
I add the template because since I am using the formset the formset.empty-form, I imagine that I must also make changes here
new-customer.html
{{ formset.management_form }}
{% for form in formset %}
<div class="part-form">
<tr>
<td>
{{form.codigo}}
</td>
<td>
{{form.descripcion}}
</td>
</tr>
</div>
{% endfor %}
<div class="part-form table-responsive" id="empty-row">
<table class="table table-bordered table-nowrap align-middle">
<tr>
<td>{{formset.empty_form.codigo}}</td>
<td>{{formset.empty_form.descripcion}}</td>
<td>{{formset.empty_form.quantity}}</td>
<td>{{formset.empty_form.unit_price}}</td>
<td>{{formset.empty_form.descuento_parte}}</td>
<td>{{formset.empty_form.total_price}}</td>
<td>{{formset.empty_form.tax_free}}</td>
<td>{{formset.empty_form.comprado_cliente}}</td>
</tr>
</table>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
