Browse Source

category slug url updated .

master
Mohsen Taba 5 months ago
parent
commit
80575c31f8
  1. 6
      apps/hadis/docs.py
  2. 2
      apps/hadis/urls.py
  3. 6
      apps/hadis/views/hadis.py

6
apps/hadis/docs.py

@ -300,12 +300,12 @@ hadis_list_swagger = swagger_auto_schema(
tags=['Hadis'],
manual_parameters=[
openapi.Parameter(
'category_id',
'category_slug',
openapi.IN_PATH,
description="Unique identifier of the Hadis category. Must be a valid category ID that exists in the system.",
type=openapi.TYPE_INTEGER,
type=openapi.TYPE_STRING,
required=True,
example=1
example='-330'
),
openapi.Parameter(
'page',

2
apps/hadis/urls.py

@ -24,7 +24,7 @@ urlpatterns = [
path('categories/', CategoriesView.as_view(), name='categories'), # ← Least specific LAST
# Hadis paths
path('category/<int:category_id>/', HadisListView.as_view(), name='hadis-list'),
path('category/<str:category_slug>/', HadisListView.as_view(), name='hadis-list'),
path('arguments/', HadisMainListView.as_view(), name='hadis-main-list'),
# Narrator paths

6
apps/hadis/views/hadis.py

@ -81,12 +81,12 @@ class HadisListView(ListAPIView):
return self.list(request, *args, **kwargs)
def get_queryset(self):
category_id = self.kwargs.get('category_id')
if not HadisCategory.objects.filter(id=category_id).exists():
category_slug = self.kwargs.get('category_slug')
if not HadisCategory.objects.filter(slug=category_slug).exists():
return Hadis.objects.none()
return Hadis.objects.filter(
category_id=category_id,
category__slug=category_slug,
status=True
).order_by('number').annotate(
# distinct=True is CRITICAL here.

Loading…
Cancel
Save