Browse Source

feat(hadis): filter root categories by default in CategoriesBySectView for accurate total counts

- Add is_root query param filter defaulting to true (parent__isnull=True) in CategoriesBySectView
- Ensure pagination count returns total count of root categories for the sect
master
Mohsen Taba 3 weeks ago
parent
commit
aaa27d086c
  1. 12
      apps/hadis/views/category.py

12
apps/hadis/views/category.py

@ -399,7 +399,17 @@ class CategoriesBySectView(ListAPIView):
def get_queryset(self):
sect_type = self.kwargs.get('sect_type')
return HadisCategory.objects.filter(sect__sect_type=sect_type)
queryset = HadisCategory.objects.filter(
sect__sect_type=sect_type,
sect__is_active=True
)
is_root = self.request.query_params.get('is_root', 'true').lower()
if is_root in ['true', '1']:
queryset = queryset.filter(parent__isnull=True)
elif is_root in ['false', '0']:
queryset = queryset.filter(parent__isnull=False)
return queryset.order_by('order', 'id')
@categories_by_sect_swagger
def get(self, request, *args, **kwargs):

Loading…
Cancel
Save