I have 3 sets of forms in one template. Only one will be displayed at a given time (the other two are completely hidden):
<form style="display: none;">
All 3 forms are displayed with default values and must be valid even if data has not been entered.
However, I would like to know which one was sent when I check view.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()
return render(request, 'submitted.html')
The problem is that I do not want f2 or f3 to be saved if only f1 was submitted (each set of forms has its own submit button). The "# Do many of calculate ..." part is quite extensive, and I don’t want to copy the code again unnecessarily.
How can I use the same view, but save and perform calculations only for the presented set of forms?