def posts(self, request, pk=None):
    owner = self.get_object()
posts = Post.objects.filter(owner=owner)
context = {'request': request}
post_serializer = PostSerializer(posts, many=True, context=context)
return Response(post_serializer.data)
Nested resources in Django REST Framework