I have 3 formsets in a single template. Only one would be visible at a given time (the other two are hidden entirely):
<form style="display: none;">
All 3 forms are rendered with default values and should be valid even if no data was entered.
However, I would like to know which one was submitted when I validate the views.py.
In views.py I have the following:
def submitted(request):
f1 = formset1(request.POST)
f2 = formset2(request.POST)
f3 = formset3(request.POST)
if f1.is_valid() or f2.is_valid() or f3.is_valid():
f1.save()
f2.save()
f3.save()
# Do a lot of calculations...
return render(request, 'submitted.html')
The problem is that I don't want f2 or f3 saved if only f1 was submitted (each formset has their own submit button). The '# Do a lot of calculations...' part is quite extensive and I don't want to replicate the code unnecessarily.
How can I use the same view, but only save and do the calculations for only the submitted formset?
request.POST
. – Shavonneshaw