Question

I have a GAE Datastore table with an array field in it (containing a few strings). I would like to filter this table, based on all array fields that contain a specific string. How can i do that ? I didn't see a 'contains' operator in GQL, and the 'in' operator works the other way around. Do I just need to loop over all entities and do the check myself ?

(P.S. I'm using Python in my work with GAE).

Was it helpful?

Solution

just use equals, for example:

class MyModel(db.Model):
  colors = db.StringListProperty()

MyModel(colors=['red', 'blue']).put()
MyModel(colors=['green', 'blue']).put()
MyModel(colors=['red', 'green']).put()

color = 'red'
query = MyModel.gql('WHERE colors = :1', color)
models = query.fetch(10)

assert len(models) == 2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top