How to do nested Django SELECT?

django, mysql, python

Solution

As pccardune says, you get the relevant users like this:

friendships = Friendship.objects.filter(from_friend=some_user)

But in fact you can pass this directly into your next query:

second_select = Whatever.objects.filter(friend__in=friendships)

Problem

``` class Friendship(models.Model): from_friend = models.ForeignKey(User, related_name='friend_set') to_friend = models.ForeignKey(User, related_name='to_friend_set') ``` I'd like to SELECT all to_friends that have from_friend = a certain User. Then, I'd like to pass to_friends to inside filter in another .objects.filter(). Is this the way to do it? Thanks!

Original source