Skip to content

Instantly share code, notes, and snippets.

@mentix02
Created August 27, 2020 19:58
Show Gist options
  • Save mentix02/d9b9b26322128fc0fddcc3ade61d0e7b to your computer and use it in GitHub Desktop.
Save mentix02/d9b9b26322128fc0fddcc3ade61d0e7b to your computer and use it in GitHub Desktop.
class FeedAPIView(ListAPIView):
serializer_class = PostSerializer
permission_classes = (IsAuthenticated,)
def get_queryset(self) -> QuerySet:
user = self.request.user
followers = user.following
follower_ids = list(followers.values_list('id', flat=True)) + [user.id]
return Post.objects.filter(user__in=follower_ids).order_by('-timestamp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment