feat: Add my posts view

This commit is contained in:
jhynsoo 2023-11-01 01:14:02 +09:00
parent cddefe5de4
commit 3cd7228c05

View File

@ -71,6 +71,19 @@ class PostViewset(ActionBasedMixin, ModelViewSet):
"create": [AllowAny], "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): def perform_create(self, serializer):
serializer.save(author=self.request.user) serializer.save(author=self.request.user)