0

I asked a similar question earlier today:
I have the following, table / class:

 Class UserFriend(model.Model):
      user = models.ForeignKey(User, related_name='friend_users' )
      friend = models.ForeignKey(User, related_name='friend_friends')
      active = models.BooleanField()

where User is the built-in auth_user class, I want to get only the friends, not the userfriends object where user is a specific user.

I'm looking to do the following SQL:

 select u.* from auth_user u, user_friend uf where u.user_id = 5 
    and u.id = uf.friend_id  
    and active=1 --- where user_id = the user being queried..

1 Answer 1

1

If user is the one you want friends for:

user.friend_users.filter(active=True).values_list('friend', flat=True)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.