1π
β
In your method save()
of BaseFormSetValidation
you are checking for value:
if form.cleaned_data.get(day):
The value 0
is falsy, so the if condition will be False
and the conditional will not run.
None
, 0
, False
are falsy values.
Instead, you can explicitly check for None
:
class BaseFormSetValidation(BaseModelFormSet):
...
def save(self, commit=True):
super(BaseFormSetValidation, self).save(commit)
from isoweek import Week
for form in self.forms:
week = Week(form.instance.year, form.instance.week)
for day in DAYS:
if form.cleaned_data.get(day) is not None:
date = week.day(int(day[-1]) - 1)
TimesheetEntry.objects.update_or_create(
timesheet=form.instance,
date=date,
defaults={'hours': form.cleaned_data.get(day)}
)
π€NKSM
Source:stackexchange.com