@ -134,9 +134,18 @@ class HadisCategorySelectSerializer(serializers.ModelSerializer):
return Hadis . objects . filter ( category = obj , status = True ) . exists ( )
def get_children_count ( self , obj ) :
""" Get count of active children categories that have children or hadis """
children = obj . get_children ( ) . filter ( sect = obj . sect )
return len ( children )
# """Get count of active children categories that have children or hadis"""
# children = obj.get_children().filter(sect=obj.sect)
# return len(children)
"""
Calculates the total number of Hadiths in this category
and all its descendants ( sub - categories ) .
"""
# 1. Get all descendants of this category (including itself)
family_tree = obj . get_descendants ( include_self = True )
# 2. Count all Hadiths that belong to any category in this tree
return Hadis . objects . filter ( category__in = family_tree ) . count ( )
def get_hadis_count ( self , obj ) :
return len ( Hadis . objects . filter ( category = obj ) )
@ -170,9 +179,18 @@ class HadisCategorySelectSourceSerializer(serializers.ModelSerializer):
return Hadis . objects . filter ( category = obj , status = True ) . exists ( )
def get_children_count ( self , obj ) :
""" Get count of active children categories that have children or hadis """
children = obj . get_children ( ) . filter ( sect = obj . sect , source_type = obj . source_type )
return len ( children )
# """Get count of active children categories that have children or hadis"""
# children = obj.get_children().filter(sect=obj.sect)
# return len(children)
"""
Calculates the total number of Hadiths in this category
and all its descendants ( sub - categories ) .
"""
# 1. Get all descendants of this category (including itself)
family_tree = obj . get_descendants ( include_self = True )
# 2. Count all Hadiths that belong to any category in this tree
return Hadis . objects . filter ( category__in = family_tree ) . count ( )
def get_hadis_count ( self , obj ) :
return len ( Hadis . objects . filter ( category = obj ) )