feat: Add my posts view
This commit is contained in:
parent
cddefe5de4
commit
3cd7228c05
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user