Home Ask Login Register

Developers Planet

Your answer is one click away!

abhishek February 2016

filter by id in ndb model

I am using ndb model as my databse. what i am trying to do is that filter the result on the basis of list of ids. i have my model like :

class Photo(ndb.Model):
   userid = ndb.StringProperty()

   source = ndb.StringProperty()
   handle = ndb.StringProperty()
   sourceid =ndb.StringProperty()

So i am trying query like this:


I have also tried :


where photoid_list is the list of ids. Help me out to solve it.


Anentropic February 2016

There are examples in the docs:

So it looks like your query should be:


Brent Washburne February 2016

I would suggest that you create keys from each id and then get them all at once:

photo_keys = [ndb.Key(Photo, id) for id in photoid_list]
photos = ndb.get_multi(photo_keys)

The advantage is that a get is faster than a query. Also, ndb will memcache the entities by key and make subsequent gets even faster.

Post Status

Asked in February 2016
Viewed 2,003 times
Voted 13
Answered 2 times


Leave an answer

Quote of the day: live life