views:

224

answers:

2

I need to filter entities based on one of their ListProperties having a certain element present. So kind of like:

entities.filter('listProp IN ',element) except where listProp and element are reversed if you see what I mean.

Anyone know how to filter like this?

A: 

Ok so it turns out the IN equality clause takes care of this case for lists automatically.

As in it does a for ... each on the list of elements to be searched for and if any one of them is present in the ListProperty for each entity it will return that entity.

rutherford
No loop required - each item of a list property is indexed separately, so the query can find all matching entities in O(n) time.
Nick Johnson
thanks Nick, prob my language was too loose there - will edit
rutherford
+1  A: 

If I understand you correctly, you want to find all entities which have that particular element present. You should be able to use: entities.filter('listProp =', element)

Look at: http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#ListProperty

It says, "list_property = value tests if the value appears anywhere in the list".

DF