Browse Source

has_parent option added for hadith categories api

master
Mohsen Taba 4 hours ago
parent
commit
a87b7c84e6
  1. 18
      apps/hadis/serializers/category.py
  2. 1
      apps/hadis/views/category.py

18
apps/hadis/serializers/category.py

@ -166,13 +166,17 @@ class HadisCategorySelectSerializer(serializers.ModelSerializer):
children_count = serializers.SerializerMethodField() children_count = serializers.SerializerMethodField()
has_hadis = serializers.SerializerMethodField() has_hadis = serializers.SerializerMethodField()
hadis_count= serializers.SerializerMethodField() hadis_count= serializers.SerializerMethodField()
has_parent = serializers.SerializerMethodField()
title = LocalizedField() title = LocalizedField()
description =LocalizedField() description =LocalizedField()
class Meta: class Meta:
model = HadisCategory model = HadisCategory
fields = ['id', 'title', 'source_type','slug', 'sect_id', fields = ['id', 'title', 'source_type','slug', 'sect_id',
'sect_type','description','children_count','has_hadis','hadis_count', 'share_link', 'xmind_share_link']
'sect_type','description','children_count','has_hadis','hadis_count', 'has_parent', 'share_link', 'xmind_share_link']
def get_has_parent(self, obj):
return obj.parent_id is not None
def get_has_hadis(self, obj): def get_has_hadis(self, obj):
"""Check if category can have hadis (no active children) and has hadis""" """Check if category can have hadis (no active children) and has hadis"""
@ -212,6 +216,7 @@ class HadisCategorySelectSourceSerializer(serializers.ModelSerializer):
children_count = serializers.SerializerMethodField() children_count = serializers.SerializerMethodField()
has_hadis = serializers.SerializerMethodField() has_hadis = serializers.SerializerMethodField()
hadis_count = serializers.SerializerMethodField() hadis_count = serializers.SerializerMethodField()
has_parent = serializers.SerializerMethodField()
title = LocalizedField() title = LocalizedField()
description = LocalizedField() description = LocalizedField()
@ -219,7 +224,10 @@ class HadisCategorySelectSourceSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = HadisCategory model = HadisCategory
fields = ['id', 'title', 'source_type','slug', 'sect_id', fields = ['id', 'title', 'source_type','slug', 'sect_id',
'sect_type','description','children_count','has_hadis','hadis_count', 'share_link', 'xmind_share_link']
'sect_type','description','children_count','has_hadis','hadis_count', 'has_parent', 'share_link', 'xmind_share_link']
def get_has_parent(self, obj):
return obj.parent_id is not None
def get_has_hadis(self, obj): def get_has_hadis(self, obj):
"""Check if category can have hadis (no active children) and has hadis""" """Check if category can have hadis (no active children) and has hadis"""
@ -253,6 +261,7 @@ class CategorySerializer(serializers.ModelSerializer):
children_count = serializers.SerializerMethodField() children_count = serializers.SerializerMethodField()
has_hadis =serializers.SerializerMethodField() has_hadis =serializers.SerializerMethodField()
hadis_count=serializers.SerializerMethodField() hadis_count=serializers.SerializerMethodField()
has_parent = serializers.SerializerMethodField()
title = LocalizedField() title = LocalizedField()
description = LocalizedField() description = LocalizedField()
@ -261,7 +270,10 @@ class CategorySerializer(serializers.ModelSerializer):
model = HadisCategory model = HadisCategory
fields = ['id', 'title', 'sect_id', 'sect_type','source_type', fields = ['id', 'title', 'sect_id', 'sect_type','source_type',
'description','slug', 'description','slug',
'children_count','has_hadis','hadis_count', 'share_link', 'xmind_share_link']
'children_count','has_hadis','hadis_count', 'has_parent', 'share_link', 'xmind_share_link']
def get_has_parent(self, obj):
return obj.parent_id is not None
def get_children_count(self, obj): def get_children_count(self, obj):
# """Get count of active children categories that have children or hadis""" # """Get count of active children categories that have children or hadis"""

1
apps/hadis/views/category.py

@ -196,6 +196,7 @@ class HadisCategoryTreeView(ListAPIView):
'hadis_count': category.direct_hadis_count, 'hadis_count': category.direct_hadis_count,
'children_count': recursive_counts.get(category.id, 0), 'children_count': recursive_counts.get(category.id, 0),
'has_hadis': has_hadis, 'has_hadis': has_hadis,
'has_parent': category.parent_id is not None,
'hadis_ids': hadis_ids_map.get(category.id, []) if has_hadis else [], 'hadis_ids': hadis_ids_map.get(category.id, []) if has_hadis else [],
# 👇 کلید جدید: تزریق دیتای قرآن دقیقاً داخل نودِ کتگوری # 👇 کلید جدید: تزریق دیتای قرآن دقیقاً داخل نودِ کتگوری
'quran_data': quran_data_map.get(category.id, None) if category.source_type == HadisCategory.SourceType.QURAN else None, 'quran_data': quran_data_map.get(category.id, None) if category.source_type == HadisCategory.SourceType.QURAN else None,

Loading…
Cancel
Save