fix chat route

This commit is contained in:
Parsa Nazer
2025-05-22 14:23:54 +03:30
parent ffce23faaf
commit cd15118921
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
from django.urls import path
from django.urls import path, re_path
from . import views
urlpatterns = [
path('product/<int:pk>', views.ProductChatView.as_view(), name='product-chat-view'),
re_path(r'^product/(?P<slug>[\w\u0600-\u06FF\-]+)$', views.ProductChatView.as_view(), name='product-chat-view'),
]
+2 -2
View File
@@ -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)