我试图弄清楚如何在django模型查询中使用IN关键字。Django模型使用关键字IN
我试图取代:
db = database.connect()
c = db.cursor()
c.execute("SELECT MAX(Date) FROM `Requests` WHERE UserId = %%s AND VIN = %%s AND Success = 1 AND RptType in %s" % str(cls.SuperReportTypes), (userID, vin))
有了这个:
myrequests = Request.objects.filter(user=userID, vin = vin, report_type in cls.SuperReportTypes)
myrequests.aggregate(Max('Date'))
我得到一个:
SyntaxError: non-keyword arg after keyword arg (<console>, line 1)
当我删除结束"report_type in cls.SuperReportTypes"
查询功能正常。
我认识到在管理结果集的查询后有一种方法可以做到这一点,但我希望以MYSQL能够执行的方式处理这个问题。