Class UserFriend(model.Model):
user = models.ForeignKey(User, related_name='friend_users' )
friend = models.ForeignKey(User, related_name='friend_friends')
active = models.BooleanField()
其中User是内置的auth_user类,我想只获取朋友,而不是用户是特定用户的userfriends对象。
我正在寻找以下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..
答案 0 :(得分:1)
如果用户是您想要的朋友:
user.friend_users.filter(active=True).values_list('friend', flat=True)