Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering by entity key name in Google App Engine on Python

On Google App Engine to query the data store with Python, one can use GQL or Entity.all() and then filter it. So for example these are equivalent

gql = "SELECT * FROM User WHERE age >= 18"
db.GqlQuery(gql)

and

query = User.all()
query.filter("age >=", 18)

Now, it's also possible to query things by key name. I know that in GQL you do it like this

gql = "SELECT * FROM User WHERE __key__ >= Key('User', 'abc')"
db.GqlQuery(gql)

But how would you now use filter to do the same?

query = User.all()
query.filter("__key__ >=", ?????)
like image 407
Bemmu Avatar asked Mar 30 '10 10:03

Bemmu


2 Answers

from google.appengine.api.datastore import Key
query.filter("__key__ >=", Key.from_path('User', 'abc'))
like image 67
Bemmu Avatar answered Nov 16 '22 03:11

Bemmu


For me a similar way worked, while the "from_path" function did not worked in my case, this one did:

from google.appengine.api.datastore import Key

key = Key(your_string_with_key)
query.filter("__key__ = ", key)
like image 20
Hannes Avatar answered Nov 16 '22 03:11

Hannes