Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类型为'的参数;非类型';在django froms中不可使用_Django_Django Forms - Fatal编程技术网

类型为'的参数;非类型';在django froms中不可使用

类型为'的参数;非类型';在django froms中不可使用,django,django-forms,Django,Django Forms,若查询中并没有返回行,那个么它将引发异常 异常类型:TypeError 异常值: 类型为“NoneType”的参数不可iterable 提前感谢如果不是无,您只能迭代res。此外,您需要返回cleaned_数据,而不是self.cleaned_数据 def clean(self): """ Override the default clean method to check whether this course has been already inputted.

若查询中并没有返回行,那个么它将引发异常 异常类型:TypeError 异常值:
类型为“NoneType”的参数不可iterable
提前感谢

如果不是
,您只能迭代
res
。此外,您需要返回
cleaned_数据
,而不是
self.cleaned_数据

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

我认为您可以使用和简化代码:

不需要使用raw或foorloop

我不知道你是模特,你问得对吗?(我的问题对吗?)


在哪一行?如果它在
for
循环中,那么
res
的值是多少?@AugustoMen它在for循环中提升为什么你有
tbmstaapprovalsched
类?你为什么不用django ORM?
def clean(self):
    """ 
    Override the default clean method to check whether this course has
    been already inputted.
    """    
    cleaned_data = super(tbmstappraisalschedForm, self).clean()

    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 = '{}' AND (('{}' BETWEEN sdtFromDate AND sdtToDate)
          OR ('{}' BETWEEN sdtFromDate and sdtToDate))"""
    res = tbmstappraisalsched.objects.raw(qry.format(depart_id.pk, fromdate,
        todate))

    if res:
        for re in res:
            if re.intAppSchedID != pk:
                msg = "The slot for selected department and selected dates exists"
                raise ValidationError(msg)

    return cleaned_data
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 

      res = tbmstappraisalsched.objects.filter( 
          Q(sdtFromDate__lt=fromdate,sdtToDate__gt=fromdate) |  \
          Q(sdtFromDate__lt=todate,sdtToDate__gt=todate), ~Q(intAppSchedID=pk),
          intDeptID=depart_id.pk,
      )          

      if res.exists():
          msg = "The slot for selected department and selected dates exists"
          raise ValidationError(msg)
      else:
          return self.cleaned_data