Browse Source

feat(hadis): support source_type, sect_type, sect, and has_hadith filtering in admin category viewset

master
Mohsen Taba 3 weeks ago
parent
commit
d5a69bd539
  1. 20
      apps/hadis/views_admin.py

20
apps/hadis/views_admin.py

@ -150,8 +150,26 @@ class DovodiHadisCategoryViewSet(ModelViewSet):
| Q(source_type__icontains=search_query) | Q(source_type__icontains=search_query)
) )
source_type = self.request.query_params.get("source_type") 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) 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") return queryset.order_by("-id")

Loading…
Cancel
Save