Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering models with ReferenceProperties

I'm using google app engine, and am having trouble writing querys to filter ReferenceProperties.

eg.

class Group(db.Model):
    name = db.StringProperty(required=True)
    creator = db.ReferenceProperty(User)

class GroupMember(db.Model):
    group = db.ReferenceProperty(Group)
    user = db.ReferenceProperty(User)

And I have tried writing something like this:

members = models.GroupMember.all().filter('group.name =', group_name)

and various other things that don't work. Hopefully someone can give me a prod in the right direction...

like image 251
wodemoneke Avatar asked Jan 15 '09 19:01

wodemoneke


1 Answers

If your groups are uniquely named, then your "group.name" is a unique identifier of a Group entity.

That means you can write:

  members = models.GroupMember.all().filter(
    "group =",model.Group.gql("WHERE name=:1", group_name).get()
    )

though you only need to do that if you don't already have the group entity lying around in the stack somewhere.

Google's essay on many-to-many with appengine is here.

like image 53
Thomas L Holaday Avatar answered Oct 20 '22 04:10

Thomas L Holaday