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' の引数は反復可能ではありません よろしくお願いします