1 2 3 4 5 6 7 8 9 10 11 | class Friend(models.Model):
from = ForeignKey('User', related_name='friends_of_me')
to = ForeignKey('User', related_name='my_friends')
def first_degree(user):
return user.my_friends_set.all()
def second_degree(user):
# Totally bogus syntax below:
return user.my_friends_set.my_friends_set.all()
|
More like this
- SelectRelatedManager by realmac 1 year, 9 months ago
- Querying on existence of a relationship by ubernostrum 5 years, 10 months ago
- Lightweight querysets by sardarnl 21 hours, 59 minutes ago
- Annotate queryset with comment count by fivethreeo 4 years, 8 months ago
- CategoriesField by fongandrew 3 years, 10 months ago
Comments
You can try smth like:
User.objects.filter(friendtofriend__to=user)
#
#