App Engine Datastore IN Operator - how to use?

Reading: http://code.google.com/appengine/docs/python/datastore/gqlreference.html

I want to use:

: = IN

but I'm not sure how to make it work. Let's pretend that

class User(db.Model):
    name = db.StringProperty()

class UniqueListOfSavedItems(db.Model):
    str = db.StringPropery()
    datesaved = db.DateTimeProperty()

class UserListOfSavedItems(db.Model):
    name = db.ReferenceProperty(User, collection='user')
    str = db.ReferenceProperty(UniqueListOfSavedItems, collection='itemlist')

How can I execute a query that gets me a list of saved items for a user? Obviously I can do:

q = db.Gql("SELECT * FROM UserListOfSavedItems WHERE name :=", user[0].name)

but it gives me a list of keys. I now want to take this list and get it in the query to get the str field from UniqueListOfSavedItems. I thought I could do:

q2 = db.Gql("SELECT * FROM UniqueListOfSavedItems WHERE := str in q")

but something is wrong ... any ideas? This (I am at work, so I can not check it now):

q2 = db.Gql("SELECT * FROM UniqueListOfSavedItems __key__ := str in q)

side of the note: what a devilishly difficult problem to find, because all I really care about is the IN operator.

+3
2

, - . :

#and this should get me the items that a user saved
useritems = db.get(saveditemkeys)

( , - db.get 0 .)

, ? , db.get 20-40 . , (GQL ) 160-200 . , ! IN Python , . , IN 10 , 10 160 -, 1,6 . db.get, , 30 .

+9

+1 , . , .

usersaveditems = User.Gql("Select * from UserListOfSavedItems where user =:1", userkey)

saveditemkeys = []

for item in usersaveditems:
    #this should create a list of keys (references) to the saved item table
    saveditemkeys.append(item.str())    

if len(usersavedsearches > 0):
    #and this should get me the items that a user saved
    useritems = db.Gql("SELECT * FROM UniqueListOfSavedItems WHERE __key__ in :1’, saveditemkeys)
0

Source: https://habr.com/ru/post/1710609/


All Articles