Re: ManyToMany reverse query

2009-03-12 Thread Andrew Turner
2009/3/12 Malcolm Tredinnick : > 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 l

Re: ManyToMany reverse query

2009-03-12 Thread Malcolm Tredinnick
On Thu, 2009-03-12 at 11:04 +, Andrew Turner wrote: > 2009/3/12 Malcolm Tredinnick : > > 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: > > > >

Re: ManyToMany reverse query

2009-03-12 Thread Andrew Turner
In case this isn't very clear due to my poor explanation, say I have three users: Bob, Jane and Dave. Now, Jane calls Dave a friend Bob calls Jane a friend Bob calls Dave a friend Asking who Bob calls a friend will obviously return Jane and Dave. But if I ask who is a fan of Dave, I want to ret

Re: ManyToMany reverse query

2009-03-12 Thread Andrew Turner
2009/3/12 Malcolm Tredinnick : > 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 Tha

Re: ManyToMany reverse query

2009-03-12 Thread Malcolm Tredinnick
On Thu, 2009-03-12 at 10:31 +, Andrew Turner wrote: > Hi, > > I've got a UserProfile model:- > > class UserProfile(models.Model): > user = models.ForeignKey(User, unique=True) > ... > friends = models.ManyToManyField(User, related_name='friend', blank=True) > ... > > I'm try

ManyToMany reverse query

2009-03-12 Thread Andrew Turner
Hi, I've got a UserProfile model:- class UserProfile(models.Model): user = models.ForeignKey(User, unique=True) ... friends = models.ManyToManyField(User, related_name='friend', blank=True) ... I'm trying to do a query which will return all the users who call a given user a 'fri