from django import forms
from django.db.models import Q
from django.core.exceptions import ValidationError
from schdeules.models import tbmsttemplate,tbmstreviewsched,tbtrnrevdepartments,tbtrnrevdesignations,tbmstappraisalsched,tbtrnappraisalreview,tbmstdepartment
class tbmstappraisalschedForm(forms.ModelForm):
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
qry = "SELECT intAppSchedID FROM tbMstAppraisalSched WHERE intDeptID ='"+depart_id+"' AND (('"+fromdate+"' BETWEEN sdtFromDate AND sdtToDate) OR ('"+todate+"' BETWEEN sdtFromDate AND sdtToDate))"
res = tbmstappraisalsched.objects.raw(qry)
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
class Meta:
model = tbmstappraisalsched
上面的代码抛出一个错误:异常值:不能连接'str'和'tbmstdepartment'对象
提前致谢