无法识别/未定义列字段

时间:2019-05-08 16:47:38

标签: django mongodb python-3.7

我有这个模型,这是我的查询-错误显示“ submission_date”未定义。但是“ overall_rating”-这是另一列,工作正常。我不明白原因。

class businessdata(models.Model):    
    submission_date = models.DateTimeField(null = False)
    product_id = models.CharField(max_length = 50)
    product_name = models.CharField(max_length = 150)
    model_number = models.CharField(max_length = 25)
    upc  = models.CharField(max_length = 25)
    overall_rating = models.IntegerField(null = False)

因此此查询有效...

categoryResult = businessdata.objects.filter(overall_rating = rating, product_name='XYZ')

但这不起作用...

categoryResult = 
  businessdata.objects.filter(submission_date >= fromdate, submission_date <= todate, overall_rating = 5).values(submission_date.strftime('%Y-%m-%d')).annotate(count = Count(submission_date.strftime('%Y-%m-%d')))

它说... 名称'sumission_date'未定义

2 个答案:

答案 0 :(得分:2)

您无法通过这种方式在查询中比较日期,请尝试以下操作:

  businessdata.objects.filter(submission_date__gte=fromdate, submission_date__lte=todate, overall_rating = 5)

本质上将>=替换为__gte,将<=替换为__lte

Here's the docs on date comparisons

答案 1 :(得分:0)

  

它说...名称'sumission_date'未定义

  • 您的字段名称是su b 任务日期

检查语法。