update comment url with slug
This commit is contained in:
@@ -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/<int:pk>', CommentView.as_view(), name='comment-views'),
|
||||
re_path(r'^(?P<slug>[\w\u0600-\u06FF\-]+)/$', ProductView.as_view(), name='product-detail'),
|
||||
re_path(r'^comments/(?P<slug>[\w\u0600-\u06FF\-]+)$', CommentView.as_view(), name='comment-views'),
|
||||
re_path(r'^(?P<slug>[\w\u0600-\u06FF\-]+)$', ProductView.as_view(), name='product-detail'),
|
||||
path('', AllProductsView.as_view(), name='category-products'),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user