def clean(self):
"""
Override the default clean method to check whether this course has been already inputted.
"""
cleaned_data = super(tbmstappraisalschedForm, self).clean()
#appsched_id = str(self.cleaned_data.get('intAppSchedID'))
depart_id = self.cleaned_data.get('intDeptID')
fromdate = str(self.cleaned_data.get('sdtFromDate'))
todate = str(self.cleaned_data.get('todate'))
pk=self.instance.pk
#if tbmstappraisalsched.objects.filter(intDeptID=depart_id).exclude(pk=self.instance.pk).exists():
#qry = "SELECT intAppSchedID FROM tbMstAppraisalSched WHERE intDeptID ='"+depart_id+"' AND (('"+fromdate+"' BETWEEN sdtFromDate AND sdtToDate) OR ('"+todate+"' BETWEEN sdtFromDate AND sdtToDate))"
qry = """SELECT intAppSchedID FROM tbMstAppraisalSched WHERE intDeptID = '{}' AND (('{}' BETWEEN sdtFromDate AND sdtToDate) OR ('{}' BETWEEN sdtFromDate and sdtToDate))"""
res = tbmstappraisalsched.objects.raw(qry.format(depart_id.pk, fromdate, todate))
for re in res:
if(re.intAppSchedID != pk):
msg = "The slot for selected department and selected dates exists"
raise ValidationError(msg)
else:
return self.cleaned_data
如果查询中没有返回行,那么它会引发异常异常类型:TypeError 异常值:
“NoneType”类型的参数不可迭代提前谢谢