On Thu, 2009-03-12 at 11:04 +0000, Andrew Turner wrote:
> 2009/3/12 Malcolm Tredinnick <malc...@pointy-stick.com>:
> > The second one is close. However, since "user" is a User object, you
> > need to be a little more careful in the filter comparison and filter
> > against the UserProfile.user attribute. Thus:
> >
> >        User.objects.filter(friend__user=user)
> >
> > Regards,
> > Malcolm
> 
> Thanks for the reply.
> 
> User.objects.filter(friend__user=user) seems to be returning the
> people who 'user' calls a friend, not those who calls 'user' a
> friend...?

Aah... sorry. Too quick on the draw, there. :-)

This does what you're after:

        User.objects.filter(userprofile__friends=user)
        
UserProfile.objects.filter(friends=user) is correct if you want the
respective UserProfile objects back, but it sounds like you want the
User objects, so you have to traverse the relation back to UserProfile
and then filter.
        
Regards,
Malcolm



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

Reply via email to