From d5a69bd539e544d2ba9b794e602e423fa3777e59 Mon Sep 17 00:00:00 2001 From: mohsentaba Date: Mon, 12 Oct 2026 11:33:14 +0330 Subject: [PATCH] feat(hadis): support source_type, sect_type, sect, and has_hadith filtering in admin category viewset --- apps/hadis/views_admin.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/apps/hadis/views_admin.py b/apps/hadis/views_admin.py index 4af1597..ae4f7c1 100644 --- a/apps/hadis/views_admin.py +++ b/apps/hadis/views_admin.py @@ -150,8 +150,26 @@ class DovodiHadisCategoryViewSet(ModelViewSet): | Q(source_type__icontains=search_query) ) source_type = self.request.query_params.get("source_type") - if source_type: + if source_type and source_type != "all": queryset = queryset.filter(source_type=source_type) + sect_type = self.request.query_params.get("sect_type") + if sect_type and sect_type != "all": + queryset = queryset.filter(sect__sect_type=sect_type) + sect_id = self.request.query_params.get("sect") + if sect_id and sect_id != "all": + queryset = queryset.filter(sect_id=sect_id) + has_hadith = self.request.query_params.get("has_hadith") + if has_hadith is not None and has_hadith != "all": + if str(has_hadith).lower() in ["false", "0"]: + queryset = queryset.filter(annotated_has_hadith=False) + elif str(has_hadith).lower() in ["true", "1"]: + queryset = queryset.filter(annotated_has_hadith=True) + is_topic = self.request.query_params.get("is_topic") + if is_topic is not None and is_topic != "all": + if str(is_topic).lower() in ["false", "0"]: + queryset = queryset.filter(annotated_has_hadith=False) + elif str(is_topic).lower() in ["true", "1"]: + queryset = queryset.filter(annotated_has_hadith=True) return queryset.order_by("-id")