title: Django-DRF See all posts from friends
body: <p>I just started toying around with the Django Rest Framework, so I'm still not entirely sure what exactly is going on. But I have a user model, a friend model, and a post model, I also have my serializers and views in order. But, I can't figure out how to return all the posts from my user's friends. Any help would be greatly appreciated.</p>
  
  <p>models.py</p>
  
  <pre><code>class CustomUser(AbstractBaseUser, PermissionsMixin):
      email = models.EmailField('email address', unique=True, db_index=True)
      password1 = models.CharField(max_length=50)
      username = models.CharField('username', max_length=50, unique=True, db_index=True)
      image = models.FileField(upload_to='photos', null=True, blank=True)
      joined = models.DateTimeField(auto_now_add=True)
      is_active = models.BooleanField(default=True)
      is_admin = models.BooleanField(default=False)
      date_joined = models.DateTimeField(_('date joined'), default=timezone.now)
  
      USERNAME_FIELD = 'username'
      REQUIRED_FIELDS = []
  
      objects = CustomUserManager()
  
      def __unicode__(self):
          return self.username
  
      class Meta:
          unique_together = (('username', 'password1'),)
  
  
  
  class Friendship(models.Model):
      created_at = models.DateTimeField(auto_now_add=True, editable=False)
      creator = models.ForeignKey(CustomUser, related_name="friendship_creator")
      friend = models.ForeignKey(CustomUser, related_name="friends")
  
  
  class Post(models.Model):
      poster = models.ForeignKey(CustomUser)
      body = models.CharField(max=200)
  
      def save(self, *args, **kwargs):
          super(Post, self).save(*args, **kwargs)
  </code></pre>
  
  <p>serializers.py</p>
  
  <pre><code>class FriendSerializer(HyperlinkedModelSerializer):
      class Meta:
          model = Friendship
          fields = ('creator', 'friend', 'created_at')
          readonly_fields = 'created_at'
  
  
  class CustomUserSerializer(HyperlinkedModelSerializer):
      friends = FriendSerializer(many=True)
  
      class Meta:
          model = CustomUser
          fields = ('email', 'username', 'password1', 'image', 'friends')
          readonly_fields = 'image'
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>class FriendViewSet(ModelViewSet):
      queryset = CustomUser.objects.all()
      serializer_class = FriendSerializer
  
  
  class UserProfileViewSet(RetrieveModelMixin, UpdateModelMixin, GenericViewSet):
      queryset = CustomUser.objects.all()
      serializer_class = CustomUserSerializer
  </code></pre>