friends = user.friends

This is a query for "Connections" objects.

Other method of writing

user = User.get_by_id(uid)
Connections.all().filter('friend =', user)  # user.friends

>for friend in friends:
>    print friend.user.key().id()
This will perform a query to fetch one (1) User object for every
friend(=type Connections) object.

> query = user.friends.filter('__key__', db.Key.from_path
> ('User',uid)).get()
This will always be None because there is no Connections object with a
key of a User object.

2009/5/6 Dave <ddev...@gmail.com>:
>
> Hi All, I just can seem to figure out the magic to make this work.
> Appreciate any guidance.
>
> I have the following models:
>
> Class User(db.Model)
> name = db.StringProperty()
> ...
>
> Class Connections(db.Model)
> user = db.ReferenceProperty(User, collection_name='users'
> friend = db.ReferenceProperty(User, collection_name='friends'
>
> and then I can do:
>
> user = User.get_by_id(uid)
> friends = user.friends
> for friend in friends:
>   print friend.user.key().id()
>
> and it works well.... What I can't figure out is how to filter such as
> below.
>
> query = user.friends.filter('__key__', db.Key.from_path
> ('User',uid)).get()
> (may be used to check for a duplicate connection)
> or
> query = user.friends.filter('email =', u...@blah.com).fetch()
> (grab friends email address...)
>
> Any help is greatly appreciated!
>
> Dave

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to