diff --git a/market/viewsets.py b/market/viewsets.py index dd016da..46451d5 100644 --- a/market/viewsets.py +++ b/market/viewsets.py @@ -71,6 +71,19 @@ class PostViewset(ActionBasedMixin, ModelViewSet): "create": [AllowAny], } + @action(detail=False, methods=["GET"]) + def my(self, request): + user = request.user + queryset = user.posts.all() + + page = self.paginate_queryset(queryset) + if page is not None: + serializer = PostListSerializer(page, many=True) + return self.get_paginated_response(serializer.data) + + serializer = PostListSerializer(queryset, many=True) + return Response(serializer.data) + def perform_create(self, serializer): serializer.save(author=self.request.user)