blog slug

This commit is contained in:
Parsa Nazer
2025-05-21 15:04:21 +03:30
parent bc214a2bdc
commit af45440e43
2 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -3,5 +3,5 @@ from . import views
urlpatterns = [
path('all', views.AllBlogView.as_view(), name='product-chat-view'),
path('<int:pk>', views.BlogView.as_view(), name='product-chat-view'),
path('<int:slug>', views.BlogView.as_view(), name='product-chat-view'),
]
+3 -3
View File
@@ -64,12 +64,12 @@ class BlogView(APIView):
return ip
def get(self, request, pk):
blog = get_object_or_404(BlogModel, pk=pk)
def get(self, request, slug):
blog = get_object_or_404(BlogModel, slug=slug)
if blog.is_published:
# Track views using session
client_ip = self.get_client_ip(request)
session_key = f'viewed_blog_{pk}_{client_ip}'
session_key = f'viewed_blog_{slug}_{client_ip}'
if not request.session.get(session_key):
blog.views += 1