Paul Breed
Paul Breed

Reputation: 1

Django Model use of keyword IN

I am attempting to figure out how to use the IN keyword in a django model query.

I was attempting to replace:

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))

With this:

myrequests = Request.objects.filter(user=userID, vin = vin, report_type in cls.SuperReportTypes)
myrequests.aggregate(Max('Date'))

I get a:

SyntaxError: non-keyword arg after keyword arg (<console>, line 1)

When I remove the ending "report_type in cls.SuperReportTypes" the query functions properly.

I recognize that there is a way to do this after the query managing the result set but I was hoping to deal with this in such a way that MYSQL would do the execution.

Upvotes: 0

Views: 507

Answers (2)

dm03514
dm03514

Reputation: 55952

You are using the wrong in statement

https://docs.djangoproject.com/en/dev/ref/models/querysets/#in

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798566

field__in=seq

Upvotes: 2

Related Questions