我是 django 的新手。任何人都可以帮助我使用此代码。我正在尝试计算 2 DateField 之间的持续时间然后保存。
class EmployeeCreate(CreateView):
model = Employee
form_class = EmployeeCreateForm
success_url = "/employee-list/"
def form_valid(self, form):
self.object.total_leave = (self.object.to_date - self.object.from_date).days +1
self.object.save()
return HttpResponseRedirect(self.get_success_url())