基本上我需要实现以下目标: 当用户输入开始日期和结束日期时,我应该能够在表格的任一字段中自动填充天数(不包括周六,周日和节假日)。 在数据库级别,我已经准备好表和查询来计算此内容。如何在Django中加入相同的内容?
我有请假申请和三个文件: models.py,views.py,forms.py和Leave.html文件
class Leaves(models.Model):
leaveID = models.AutoField(primary_key=True)
fromDate = models.DateField()
toDate = models.DateField()
leaveType=models.CharField(max_length=20)
noofDays = models.IntegerField(blank=True,null=True)
createdBy = models.CharField(max_length=30)
createdAt = models.DateTimeField(default=datetime.datetime.now, null=True, blank=True)
updatedAt = models.DateTimeField(default=datetime.datetime.now, null=True, blank=True)
def leave(request):
context = {'form': Leaves}
if request.method=='POST':
form = LeaveForm(request.POST)
if form.is_valid():
leaveID=request.POST.get('leaveID')
fromDate=request.POST.get('fromDates')
toDate=request.POST.get('toDate')
leaveType = request.POST.get('leaveType')
createdBy = User.objects.get(username=request.user.username)
noofDays = Dim_Date.objects.raw('select count(distinct calendarDate) from Dim_Date where isWeekday=1 and isHoliday<>1')
form.save()
return render(request,'leave/leaveconfirmation.html')
else:
return render(request,'leave/leave.html')
else:
return render(request,'leave/leave.html',context)
我应该能够根据表单中给出的from_date和to_date自动填充字段。 (后端逻辑已准备就绪)请让我知道如何将其集成到Django中。