I'm trying to execute the following query:
query = Comment.query(ancestor = userKey, ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))
The 1 equal sign (=) is how the docs said we should have it, but my app doesn't run when I have just 1 equal sign (build error). If I use two equal sign, like ancestor == userKey
, then the app runs, but I get a NameError: global name 'ancestor' is not defined
. What gives?
I also tried another variant of this query, but the same exact problem occurs:
query = Comment.query(ndb.AND(ancestor == userKey, ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate)))
You need to put the ancestor
keyword after the method positional parameters:
query = Comment.query(
ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate),
ancestor=userKey)
Alternatively, use the filters
keyword explicitly, or use the .filter()
method:
query = Comment.query(
ancestor=userKey,
filters=ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))
or
query = Comment.query(ancestor=userKey).filter(ndb.OR(Comment.modifiedDate > lastSyncDate, Comment.activityDate > lastSyncDate))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.