update comment url with slug

This commit is contained in:
Parsa Nazer
2025-05-22 14:11:33 +03:30
parent 8087f3aaa5
commit 5ed006ff49
2 changed files with 6 additions and 6 deletions
+4 -4
View File
@@ -413,17 +413,17 @@ class CommentView(APIView):
404: OpenApiTypes.OBJECT,
},
)
def get(self, request, pk):
product = get_object_or_404(ProductModel, id=pk)
def get(self, request, slug):
product = get_object_or_404(ProductModel, slug=slug)
comments = product.comments.filter(review_status__in=['not_reviwed', 'reviewed_and_confirmed'])
paginator = self.pagination_class()
paginated_comments = paginator.paginate_queryset(comments, request)
comments_ser = self.serializer_class(instance=paginated_comments, many=True)
return paginator.get_paginated_response(comments_ser.data)
def post(self, request, pk):
def post(self, request, slug):
comment_ser = CommentSerializer(data=request.data)
product = get_object_or_404(ProductModel, id=pk)
product = get_object_or_404(ProductModel, slug=slug)
if comment_ser.is_valid():
comment_ser.save(product=product, user=request.user)
return Response(comment_ser.data, status=status.HTTP_201_CREATED)