views:

40

answers:

1

A sample model:

  class Foo(db.Model):
     id = db.IntegerProperty()
     bar = db.ListProperty(int, required=True)
  1. How can I query using either Query or GqlQuery to return all Foo entities that have a given value in their bar property?

  2. If I have a list of ids, is there a single filter that will return all entities whose id property is in that list?

+2  A: 

1.

If you use an equals query on a list property, it will check all items in the list:

search = 2
results = Foo.all().filter('bar =', search).fetch()

2.

You can use an IN filter, but note that internally this makes a datastore query for each item in the list, so it may be slow, and there are also a maximum of 30 internal queries per request.

items = [1, 2, 3]
results = Foo.all().filter("id IN", items).fetch()

See Introducing Queries for details for both 1 and 2, and ListProperty for further details on 1.

Saxon Druce