|
|
|
@ -114,17 +114,8 @@ class HadisCategoryTreeSerializer(serializers.ModelSerializer): |
|
|
|
return [self.to_dict(cat) for cat in children] |
|
|
|
|
|
|
|
def get_hadis_count(self, obj): |
|
|
|
"""Get total hadis count including children categories""" |
|
|
|
# Get direct hadis count |
|
|
|
direct_count = Hadis.objects.filter(category=obj, status=True).count() |
|
|
|
|
|
|
|
# Get hadis count from all descendants |
|
|
|
descendants = obj.get_descendants().filter(sect=obj.sect) |
|
|
|
descendant_count = 0 |
|
|
|
for descendant in descendants: |
|
|
|
descendant_count += Hadis.objects.filter(category=descendant, status=True).count() |
|
|
|
|
|
|
|
return direct_count + descendant_count |
|
|
|
"""Get direct hadis count for this category only""" |
|
|
|
return Hadis.objects.filter(category=obj, status=True).count() |
|
|
|
|
|
|
|
def get_has_hadis(self, obj): |
|
|
|
"""Check if category can have hadis (no active children) and has hadis""" |
|
|
|
@ -169,6 +160,10 @@ class HadisCategoryTreeSerializer(serializers.ModelSerializer): |
|
|
|
).order_by('number').values_list('number', flat=True) |
|
|
|
) |
|
|
|
|
|
|
|
def get_children_count(self, obj): |
|
|
|
"""Get count of active children categories""" |
|
|
|
return obj.get_children().filter(sect=obj.sect).count() |
|
|
|
|
|
|
|
|
|
|
|
def to_dict(self, category, request=None): |
|
|
|
"""Convert category to dict, applying localization""" |
|
|
|
@ -183,6 +178,7 @@ class HadisCategoryTreeSerializer(serializers.ModelSerializer): |
|
|
|
'source_type': category.source_type, |
|
|
|
'hadis_count': self.get_hadis_count(category), |
|
|
|
'has_hadis': self.get_has_hadis(category), |
|
|
|
'children_count': self.get_children_count(category), |
|
|
|
'order': category.order, |
|
|
|
'thumbnail': self.get_thumbnail(category), |
|
|
|
'xmind_file': self.get_xmind_file(category), |
|
|
|
|