diff --git a/backend/product/urls.py b/backend/product/urls.py index 76c6fd8..95b4c21 100644 --- a/backend/product/urls.py +++ b/backend/product/urls.py @@ -5,7 +5,7 @@ urlpatterns = [ path('slider_category', ShowCaseProductsView.as_view(), name='category-products'), path('categories', AllCategories.as_view(), name='all-categories'), path('slider_categories', ShowCaseCategoryListView.as_view(), name='all-categories'), - path('comments/', CommentView.as_view(), name='comment-views'), - re_path(r'^(?P[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'), + re_path(r'^comments/(?P[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'), + re_path(r'^(?P[\w\u0600-\u06FF\-]+)$', ProductView.as_view(), name='product-detail'), path('', AllProductsView.as_view(), name='category-products'), ] \ No newline at end of file diff --git a/backend/product/views.py b/backend/product/views.py index 1a17238..95c8f24 100644 --- a/backend/product/views.py +++ b/backend/product/views.py @@ -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)