1👍
✅
Just save the forms that match:
if request.method == 'POST':
formset = WeeksFormset(request.POST)
if formset.is_valid():
for form in formset.forms:
instance = form.instance
if any(
f is not None
for f in [
instance.monday,
instance.tuesday,
instance.wednesday,
instance.thursday,
instance.friday,
instance.saturday,
instance.sunday,
]
):
instance.user = request.user
form.save()
# do *not* save the formset
return redirect('time')
Source:stackexchange.com