blog slug
This commit is contained in:
@@ -3,5 +3,5 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('all', views.AllBlogView.as_view(), name='product-chat-view'),
|
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'),
|
||||||
]
|
]
|
||||||
@@ -64,12 +64,12 @@ class BlogView(APIView):
|
|||||||
return ip
|
return ip
|
||||||
|
|
||||||
|
|
||||||
def get(self, request, pk):
|
def get(self, request, slug):
|
||||||
blog = get_object_or_404(BlogModel, pk=pk)
|
blog = get_object_or_404(BlogModel, slug=slug)
|
||||||
if blog.is_published:
|
if blog.is_published:
|
||||||
# Track views using session
|
# Track views using session
|
||||||
client_ip = self.get_client_ip(request)
|
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):
|
if not request.session.get(session_key):
|
||||||
blog.views += 1
|
blog.views += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user