From cd1511892177bf183da2aa26123853e8e57b01a8 Mon Sep 17 00:00:00 2001 From: Parsa Nazer Date: Thu, 22 May 2025 14:23:54 +0330 Subject: [PATCH] fix chat route --- backend/chat/urls.py | 4 ++-- backend/chat/views.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/chat/urls.py b/backend/chat/urls.py index 31c977a..94b9883 100644 --- a/backend/chat/urls.py +++ b/backend/chat/urls.py @@ -1,6 +1,6 @@ -from django.urls import path +from django.urls import path, re_path from . import views urlpatterns = [ - path('product/', views.ProductChatView.as_view(), name='product-chat-view'), + re_path(r'^product/(?P[\w\u0600-\u06FF\-]+)$', views.ProductChatView.as_view(), name='product-chat-view'), ] \ No newline at end of file diff --git a/backend/chat/views.py b/backend/chat/views.py index e677e5a..b806031 100644 --- a/backend/chat/views.py +++ b/backend/chat/views.py @@ -94,12 +94,12 @@ class ProductChatView(APIView): permission_classes = [IsAuthenticated] pagination_class = StructurePagination - def get(self, request, pk): + def get(self, request, slug): """ Retrieve all messages for a product chat. """ user = request.user - product = get_object_or_404(ProductModel, id=pk) + product = get_object_or_404(ProductModel, slug=slug) chat, created = ProductChatModel.objects.get_or_create(user=user, product=product) client = openai.OpenAI(api_key=settings.OPENAI_API_KEY)