Tagging with Appengine DataStore
I've been looking into how to implement a tagging mechanism with Appengine (Python). By using a StringListProperty, you can associate a list of tags with an entity. The model would look something like this: from google.appengine.ext import db class Sample(db.Model): name = db.StringProperty(required=True) tags = db.StringListProperty() Now, assuming we want to find the entities tagged with a given word, we can use a query like this: q = db.GqlQuery("SELECT * FROM Sample where tags = :1",'z') If we want to find all entities that have ANY of these tags (OR) we can query with GqlQuery or filter: q = db.GqlQuery("SELECT * FROM Sample where tags in :1",['a','z']) q = domain.Sample.all() q.filter("tags in ", ['b','d']) When we want to find entities with ALL of the given tags: q = db.GqlQuery("SELECT * FROM Sample where tags = :1 and tags = :2",'b','c') q = domain.Sample.all() q.filter(...