You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
613 lines
28 KiB
613 lines
28 KiB
"""
|
|
Django management command to seed mock data for hadith transmitters and related models.
|
|
Place this file in: yourapp/management/commands/seed_transmitters.py
|
|
|
|
Usage: python manage.py seed_transmitters
|
|
python manage.py seed_transmitters --clear
|
|
"""
|
|
|
|
import json
|
|
from django.core.management.base import BaseCommand
|
|
from django.utils.text import slugify
|
|
from apps.hadis.models.transmitter import (
|
|
NarratorLayer,
|
|
Transmitters,
|
|
HadisTransmitter,
|
|
TransmitterOpinion,
|
|
TransmitterOriginalText
|
|
)
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Seed the database with mock hadith transmitter data'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--clear',
|
|
action='store_true',
|
|
help='Clear existing data before seeding',
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
if options['clear']:
|
|
self.stdout.write(self.style.WARNING('Clearing existing transmitter data...'))
|
|
TransmitterOriginalText.objects.all().delete()
|
|
TransmitterOpinion.objects.all().delete()
|
|
HadisTransmitter.objects.all().delete()
|
|
Transmitters.objects.all().delete()
|
|
NarratorLayer.objects.all().delete()
|
|
self.stdout.write(self.style.SUCCESS('Data cleared successfully!'))
|
|
|
|
# Step 1: Create Narrator Layers (Tabaqat)
|
|
self.stdout.write(self.style.SUCCESS('\n📚 Creating Narrator Layers...'))
|
|
layers_data = [
|
|
{
|
|
"name": "Sahaba (Companions)",
|
|
"number": 1,
|
|
"description": "The companions of Prophet Muhammad (PBUH) who heard directly from him."
|
|
},
|
|
{
|
|
"name": "Tabi'un (Successors)",
|
|
"number": 2,
|
|
"description": "Narrators who lived after the Prophet's era and heard from the companions."
|
|
},
|
|
{
|
|
"name": "Taba' Tabi'in (Followers of Successors)",
|
|
"number": 3,
|
|
"description": "Narrators who heard from the Successors."
|
|
},
|
|
{
|
|
"name": "Later Generations",
|
|
"number": 4,
|
|
"description": "Narrators from later Islamic centuries, known for their scholarship."
|
|
},
|
|
{
|
|
"name": "Modern Era Scholars",
|
|
"number": 5,
|
|
"description": "Contemporary scholars who have specialized knowledge of hadith narration."
|
|
},
|
|
]
|
|
|
|
layers = {}
|
|
for layer_data in layers_data:
|
|
layer, created = NarratorLayer.objects.get_or_create(
|
|
number=layer_data['number'],
|
|
defaults={
|
|
'name': layer_data['name'],
|
|
'description': layer_data['description'],
|
|
'slug': slugify(layer_data['name'])
|
|
}
|
|
)
|
|
layers[layer_data['number']] = layer
|
|
status = '✓ Created' if created else '• Updated'
|
|
self.stdout.write(f"{status}: {layer.name} (Layer {layer.number})")
|
|
|
|
# Step 2: Create Transmitters (Hadith Narrators)
|
|
self.stdout.write(self.style.SUCCESS('\n👥 Creating Transmitters...'))
|
|
transmitters_data = [
|
|
{
|
|
"full_name": "Abu Hurayrah",
|
|
"kunya": "Abu Hurayrah",
|
|
"known_as": "Abd al-Rahman ibn Sakhr",
|
|
"nickname": "Father of the Kitten",
|
|
"origin": "Yamama, Arabia",
|
|
"lived_in": "Medina, Syria",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": 7,
|
|
"death_year_hijri": 58,
|
|
"age_at_death": 78,
|
|
"generation": 1,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "One of the most prolific hadith narrators, reported 5,374 ahadith.",
|
|
"narrator_layer": 1,
|
|
},
|
|
{
|
|
"full_name": "Aisha bint Abu Bakr",
|
|
"kunya": "Umm al-Mu'minin",
|
|
"known_as": "Mother of the Believers",
|
|
"nickname": "Al-Siddiqa",
|
|
"origin": "Medina",
|
|
"lived_in": "Medina",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": None,
|
|
"death_year_hijri": 58,
|
|
"age_at_death": 66,
|
|
"generation": 1,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Wife of the Prophet Muhammad (PBUH), a major source of hadith about daily life.",
|
|
"narrator_layer": 1,
|
|
},
|
|
{
|
|
"full_name": "Jabir ibn Abdullah al-Ansari",
|
|
"kunya": "Abu Abdullah",
|
|
"known_as": "Jabir",
|
|
"nickname": "Al-Ansari",
|
|
"origin": "Medina",
|
|
"lived_in": "Medina",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": 10,
|
|
"death_year_hijri": 74,
|
|
"age_at_death": 94,
|
|
"generation": 1,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "One of the long-lived companions, reported numerous ahadith on various topics.",
|
|
"narrator_layer": 1,
|
|
},
|
|
{
|
|
"full_name": "Imam Malik ibn Anas",
|
|
"kunya": "Abu Abdullah",
|
|
"known_as": "Malik",
|
|
"nickname": "Imam of Imams",
|
|
"origin": "Medina",
|
|
"lived_in": "Medina",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": 93,
|
|
"death_year_hijri": 179,
|
|
"age_at_death": 86,
|
|
"generation": 3,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "maliki",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Founder of the Maliki school of Islamic jurisprudence, compiler of Al-Muwatta.",
|
|
"narrator_layer": 3,
|
|
},
|
|
{
|
|
"full_name": "Al-Qasim ibn Muhammad",
|
|
"kunya": "Abu Muhammad",
|
|
"known_as": "Al-Qasim",
|
|
"nickname": "Son of the Rightly Guided",
|
|
"origin": "Medina",
|
|
"lived_in": "Medina",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": 38,
|
|
"death_year_hijri": 106,
|
|
"age_at_death": 68,
|
|
"generation": 2,
|
|
"reliability": "reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Son of Amir al-Mu'minin, known for his knowledge of Islamic jurisprudence.",
|
|
"narrator_layer": 2,
|
|
},
|
|
{
|
|
"full_name": "Urwa ibn al-Zubayr",
|
|
"kunya": "Abu Abdullah",
|
|
"known_as": "Urwa",
|
|
"nickname": "The Jurist",
|
|
"origin": "Medina",
|
|
"lived_in": "Medina, Mecca",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": 23,
|
|
"death_year_hijri": 94,
|
|
"age_at_death": 71,
|
|
"generation": 2,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Prominent Tabi'un scholar and transmitter of hadith from Aisha.",
|
|
"narrator_layer": 2,
|
|
},
|
|
{
|
|
"full_name": "Abdullah ibn Abbas",
|
|
"kunya": "Abu Abbas",
|
|
"known_as": "Ibn Abbas",
|
|
"nickname": "Hibr al-Ummah (The Learned Scholar of the Nation)",
|
|
"origin": "Medina",
|
|
"lived_in": "Medina, Mecca, Basra",
|
|
"died_in": "Taif",
|
|
"birth_year_hijri": 3,
|
|
"death_year_hijri": 68,
|
|
"age_at_death": 71,
|
|
"generation": 1,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Cousin of the Prophet (PBUH), famous for Quranic exegesis and hadith knowledge.",
|
|
"narrator_layer": 1,
|
|
},
|
|
{
|
|
"full_name": "Nafi' (Mawla of Ibn Umar)",
|
|
"kunya": "Abu Abdullah",
|
|
"known_as": "Nafi'",
|
|
"nickname": "The Freed Slave",
|
|
"origin": "Ethiopia",
|
|
"lived_in": "Medina",
|
|
"died_in": "Medina",
|
|
"birth_year_hijri": 25,
|
|
"death_year_hijri": 117,
|
|
"age_at_death": 92,
|
|
"generation": 2,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "sunni",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Freed slave of Abdullah ibn Umar, transmitted numerous hadith from him.",
|
|
"narrator_layer": 2,
|
|
},
|
|
{
|
|
"full_name": "Imam Ahmad ibn Hanbal",
|
|
"kunya": "Abu Abdullah",
|
|
"known_as": "Ahmad",
|
|
"nickname": "Shaykh al-Islam",
|
|
"origin": "Khorasan",
|
|
"lived_in": "Baghdad",
|
|
"died_in": "Baghdad",
|
|
"birth_year_hijri": 164,
|
|
"death_year_hijri": 241,
|
|
"age_at_death": 77,
|
|
"generation": 4,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "hanbali",
|
|
"in_sahih_muslim": False,
|
|
"in_sahih_bukhari": False,
|
|
"description": "Founder of the Hanbali school, compiler of Musnad Ahmad with 40,000+ hadith.",
|
|
"narrator_layer": 3,
|
|
},
|
|
{
|
|
"full_name": "Sufyan ibn Uyayna",
|
|
"kunya": "Abu Muhammad",
|
|
"known_as": "Sufyan",
|
|
"nickname": "Amir al-Mu'minin fil-Hadith",
|
|
"origin": "Kufa",
|
|
"lived_in": "Mecca, Kufa",
|
|
"died_in": "Mecca",
|
|
"birth_year_hijri": 107,
|
|
"death_year_hijri": 198,
|
|
"age_at_death": 91,
|
|
"generation": 3,
|
|
"reliability": "very_reliable",
|
|
"madhhab": "shafii",
|
|
"in_sahih_muslim": True,
|
|
"in_sahih_bukhari": True,
|
|
"description": "Great hadith scholar and judge, known for his exceptional memory.",
|
|
"narrator_layer": 3,
|
|
},
|
|
]
|
|
|
|
transmitters = {}
|
|
for trans_data in transmitters_data:
|
|
narrator_layer_num = trans_data.pop('narrator_layer')
|
|
narrator_layer = layers.get(narrator_layer_num)
|
|
|
|
transmitter, created = Transmitters.objects.get_or_create(
|
|
full_name=trans_data['full_name'],
|
|
defaults=trans_data
|
|
)
|
|
transmitters[trans_data['full_name']] = transmitter
|
|
status = '✓ Created' if created else '• Updated'
|
|
self.stdout.write(f"{status}: {transmitter.full_name}")
|
|
|
|
# Step 3: Create Transmitter Opinions
|
|
self.stdout.write(self.style.SUCCESS('\n💬 Creating Transmitter Opinions...'))
|
|
opinions_data = [
|
|
{
|
|
"transmitter_name": "Abu Hurayrah",
|
|
"scholar_name": "Imam al-Bukhari",
|
|
"opinion_text": "Abu Hurayrah is one of the most reliable narrators with a perfect memory and integrity.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Abu Hurayrah",
|
|
"scholar_name": "Imam Muslim",
|
|
"opinion_text": "His narrations are authentic and widely accepted in the Islamic jurisprudence.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Aisha bint Abu Bakr",
|
|
"scholar_name": "Imam al-Bukhari",
|
|
"opinion_text": "The Mother of the Believers is the most reliable source for hadith about the Prophet's household.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Jabir ibn Abdullah al-Ansari",
|
|
"scholar_name": "Ibn Hajar al-Asqalani",
|
|
"opinion_text": "His longevity allowed him to transmit from many companions and successors.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Imam Malik ibn Anas",
|
|
"scholar_name": "Imam ash-Shafi'i",
|
|
"opinion_text": "Malik is among the most knowledgeable of the Medinese scholars in jurisprudence.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Imam Malik ibn Anas",
|
|
"scholar_name": "Imam Ahmad ibn Hanbal",
|
|
"opinion_text": "Malik's narrations form the basis of sound Islamic jurisprudence.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Al-Qasim ibn Muhammad",
|
|
"scholar_name": "Ibn Hajar al-Asqalani",
|
|
"opinion_text": "Al-Qasim is a trustworthy narrator from the Tabi'un generation with reliable traditions.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Urwa ibn al-Zubayr",
|
|
"scholar_name": "Imam al-Bukhari",
|
|
"opinion_text": "Urwa is among the most knowledgeable about the traditions of the Prophet's household.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Abdullah ibn Abbas",
|
|
"scholar_name": "Imam at-Tirmidhi",
|
|
"opinion_text": "Ibn Abbas has exceptional knowledge in Quranic interpretation and hadith narration.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Nafi' (Mawla of Ibn Umar)",
|
|
"scholar_name": "Imam Muslim",
|
|
"opinion_text": "Nafi' is one of the most reliable freed slaves who transmitted authentic traditions.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Imam Ahmad ibn Hanbal",
|
|
"scholar_name": "Ibn Hajar al-Asqalani",
|
|
"opinion_text": "Ahmad ibn Hanbal's knowledge of hadith is unparalleled in his era.",
|
|
"status": "confirmed"
|
|
},
|
|
{
|
|
"transmitter_name": "Sufyan ibn Uyayna",
|
|
"scholar_name": "Imam al-Bukhari",
|
|
"opinion_text": "Sufyan is a highly reliable hadith scholar with exceptional memory.",
|
|
"status": "confirmed"
|
|
},
|
|
]
|
|
|
|
for opinion_data in opinions_data:
|
|
transmitter_name = opinion_data.pop('transmitter_name')
|
|
transmitter = transmitters.get(transmitter_name)
|
|
if transmitter:
|
|
opinion, created = TransmitterOpinion.objects.get_or_create(
|
|
transmitter=transmitter,
|
|
scholar_name=opinion_data['scholar_name'],
|
|
defaults=opinion_data
|
|
)
|
|
if created:
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
f"✓ Opinion added: {opinion_data['scholar_name']} on {transmitter_name}"
|
|
)
|
|
)
|
|
|
|
# Step 4: Create Original Texts
|
|
self.stdout.write(self.style.SUCCESS('\n📜 Creating Transmitter Original Texts...'))
|
|
original_texts_data = [
|
|
{
|
|
"transmitter_name": "Abu Hurayrah",
|
|
"title": "His Narration on Zakat",
|
|
"text": "حدثنا أبو هريرة قال: قال رسول الله صلى الله عليه وسلم: من آمن بالله واليوم الآخر فليؤد الزكاة",
|
|
"translation": [
|
|
{"language_code": "en", "text": "Abu Hurayrah narrated: The Messenger of Allah (PBUH) said: Whoever believes in Allah and the Last Day, let him pay the Zakat (alms)."},
|
|
{"language_code": "ar", "text": "أبو هريرة: من آمن بالله واليوم الآخر فليؤد الزكاة"}
|
|
],
|
|
"share_link": "https://hadith.example.com/abu-hurayrah/zakat-1"
|
|
},
|
|
{
|
|
"transmitter_name": "Aisha bint Abu Bakr",
|
|
"title": "Her Account of the Prophet's Night Prayer",
|
|
"text": "قالت عائشة: كان النبي صلى الله عليه وسلم يقوم الليل فيصلي ثلاث عشرة ركعة",
|
|
"translation": [
|
|
{"language_code": "en", "text": "Aisha said: The Prophet (PBUH) used to pray at night thirteen rak'ahs."},
|
|
{"language_code": "ar", "text": "عائشة: كان النبي يقوم الليل بثلاث عشرة ركعة"}
|
|
],
|
|
"share_link": "https://hadith.example.com/aisha/night-prayer-1"
|
|
},
|
|
{
|
|
"transmitter_name": "Jabir ibn Abdullah al-Ansari",
|
|
"title": "The Farewell Hajj Narration",
|
|
"text": "قال جابر: خرجنا مع رسول الله صلى الله عليه وسلم في حجة الوداع",
|
|
"translation": [
|
|
{"language_code": "en", "text": "Jabir narrated: We went out with the Messenger of Allah (PBUH) for the Farewell Hajj."},
|
|
{"language_code": "ar", "text": "جابر: خرجنا مع رسول الله في حجة الوداع"}
|
|
],
|
|
"share_link": "https://hadith.example.com/jabir/farewell-hajj-1"
|
|
},
|
|
{
|
|
"transmitter_name": "Imam Malik ibn Anas",
|
|
"title": "Narration on Purity and Prayer",
|
|
"text": "قال مالك: الطهارة شرط من شروط الصلاة",
|
|
"translation": [
|
|
{"language_code": "en", "text": "Malik said: Purification is a condition for the validity of prayer."},
|
|
{"language_code": "ar", "text": "مالك: الطهارة من شروط صحة الصلاة"}
|
|
],
|
|
"share_link": "https://hadith.example.com/malik/purity-1"
|
|
},
|
|
{
|
|
"transmitter_name": "Abdullah ibn Abbas",
|
|
"title": "His Commentary on Divine Justice",
|
|
"text": "قال ابن عباس: إن الله تعالى عدل لا يظلم أحدا",
|
|
"translation": [
|
|
{"language_code": "en", "text": "Ibn Abbas said: Truly Allah is Just and does not oppress anyone."},
|
|
{"language_code": "ar", "text": "ابن عباس: الله عدل لا يظلم أحدا"}
|
|
],
|
|
"share_link": "https://hadith.example.com/ibn-abbas/justice-1"
|
|
},
|
|
{
|
|
"transmitter_name": "Sufyan ibn Uyayna",
|
|
"title": "Teaching on Knowledge Seeking",
|
|
"text": "قال سفيان بن عيينة: طلب العلم فريضة على كل مسلم",
|
|
"translation": [
|
|
{"language_code": "en", "text": "Sufyan ibn Uyayna said: Seeking knowledge is an obligation for every Muslim."},
|
|
{"language_code": "ar", "text": "سفيان: طلب العلم فريضة على كل مسلم"}
|
|
],
|
|
"share_link": "https://hadith.example.com/sufyan/knowledge-1"
|
|
},
|
|
]
|
|
|
|
for text_data in original_texts_data:
|
|
transmitter_name = text_data.pop('transmitter_name')
|
|
transmitter = transmitters.get(transmitter_name)
|
|
if transmitter:
|
|
original_text, created = TransmitterOriginalText.objects.get_or_create(
|
|
transmitter=transmitter,
|
|
title=text_data['title'],
|
|
defaults=text_data
|
|
)
|
|
if created:
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
f"✓ Original text added: {text_data['title']} by {transmitter_name}"
|
|
)
|
|
)
|
|
|
|
# Step 5: Create Hadis Transmitters (Chain of narration)
|
|
self.stdout.write(self.style.SUCCESS('\n⛓️ Creating Hadis Transmitters (Chains)...'))
|
|
|
|
# Sample hadis IDs to use (you can have any ID from 1800 to 1852)
|
|
hadis_ids = list(range(1800, 1853))
|
|
|
|
# Create chains for different hadis
|
|
chains_data = [
|
|
{
|
|
"hadis_id": hadis_ids[0],
|
|
"chain": [
|
|
{"transmitter_name": "Abu Hurayrah", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Imam Malik ibn Anas", "order": 2, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[1],
|
|
"chain": [
|
|
{"transmitter_name": "Aisha bint Abu Bakr", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Urwa ibn al-Zubayr", "order": 2, "layer": 2, "status": "reliable"},
|
|
{"transmitter_name": "Imam Malik ibn Anas", "order": 3, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[2],
|
|
"chain": [
|
|
{"transmitter_name": "Jabir ibn Abdullah al-Ansari", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Al-Qasim ibn Muhammad", "order": 2, "layer": 2, "status": "reliable"},
|
|
{"transmitter_name": "Sufyan ibn Uyayna", "order": 3, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[3],
|
|
"chain": [
|
|
{"transmitter_name": "Abdullah ibn Abbas", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Nafi' (Mawla of Ibn Umar)", "order": 2, "layer": 2, "status": "reliable"},
|
|
{"transmitter_name": "Imam Ahmad ibn Hanbal", "order": 3, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[4],
|
|
"chain": [
|
|
{"transmitter_name": "Abu Hurayrah", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Sufyan ibn Uyayna", "order": 2, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[5],
|
|
"chain": [
|
|
{"transmitter_name": "Aisha bint Abu Bakr", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Al-Qasim ibn Muhammad", "order": 2, "layer": 2, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[6],
|
|
"chain": [
|
|
{"transmitter_name": "Jabir ibn Abdullah al-Ansari", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Nafi' (Mawla of Ibn Umar)", "order": 2, "layer": 2, "status": "reliable"},
|
|
{"transmitter_name": "Imam Malik ibn Anas", "order": 3, "layer": 3, "status": "reliable"},
|
|
{"transmitter_name": "Sufyan ibn Uyayna", "order": 4, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[7],
|
|
"chain": [
|
|
{"transmitter_name": "Abdullah ibn Abbas", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Urwa ibn al-Zubayr", "order": 2, "layer": 2, "status": "reliable"},
|
|
{"transmitter_name": "Imam Ahmad ibn Hanbal", "order": 3, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[8],
|
|
"chain": [
|
|
{"transmitter_name": "Abu Hurayrah", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Al-Qasim ibn Muhammad", "order": 2, "layer": 2, "status": "reliable"},
|
|
{"transmitter_name": "Imam Malik ibn Anas", "order": 3, "layer": 3, "status": "reliable"},
|
|
{"transmitter_name": "Sufyan ibn Uyayna", "order": 4, "layer": 3, "status": "reliable"},
|
|
]
|
|
},
|
|
{
|
|
"hadis_id": hadis_ids[9],
|
|
"chain": [
|
|
{"transmitter_name": "Aisha bint Abu Bakr", "order": 1, "layer": 1, "status": "reliable"},
|
|
{"transmitter_name": "Nafi' (Mawla of Ibn Umar)", "order": 2, "layer": 2, "status": "reliable"},
|
|
]
|
|
},
|
|
]
|
|
|
|
hadis_transmitter_count = 0
|
|
for chain_data in chains_data:
|
|
hadis_id = chain_data['hadis_id']
|
|
chain = chain_data['chain']
|
|
|
|
for item in chain:
|
|
transmitter = transmitters.get(item['transmitter_name'])
|
|
layer = layers.get(item['layer'])
|
|
|
|
if transmitter and layer:
|
|
hadis_trans, created = HadisTransmitter.objects.get_or_create(
|
|
hadis_id=hadis_id,
|
|
transmitter=transmitter,
|
|
order=item['order'],
|
|
defaults={
|
|
'narrator_layer': layer,
|
|
'status': item['status'],
|
|
'is_gap': False
|
|
}
|
|
)
|
|
if created:
|
|
hadis_transmitter_count += 1
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
f"✓ Chain link: Hadis {hadis_id} <- {item['transmitter_name']} (Order {item['order']})"
|
|
)
|
|
)
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(
|
|
f'\n✓ Successfully seeded transmitter data!'
|
|
)
|
|
)
|
|
self._print_summary(transmitters, hadis_transmitter_count)
|
|
|
|
def _print_summary(self, transmitters, hadis_transmitter_count):
|
|
"""Print a summary of created data"""
|
|
self.stdout.write("\n" + "="*70)
|
|
self.stdout.write(self.style.SUCCESS("TRANSMITTER DATABASE SUMMARY"))
|
|
self.stdout.write("="*70)
|
|
|
|
layers_count = NarratorLayer.objects.count()
|
|
transmitters_count = Transmitters.objects.count()
|
|
opinions_count = TransmitterOpinion.objects.count()
|
|
original_texts_count = TransmitterOriginalText.objects.count()
|
|
|
|
self.stdout.write(f"📚 Narrator Layers: {layers_count}")
|
|
self.stdout.write(f"👥 Total Transmitters: {transmitters_count}")
|
|
self.stdout.write(f"💬 Transmitter Opinions: {opinions_count}")
|
|
self.stdout.write(f"📜 Original Texts: {original_texts_count}")
|
|
self.stdout.write(f"⛓️ Hadis Transmitter Chains: {hadis_transmitter_count}")
|
|
|
|
self.stdout.write("\n" + "="*70)
|
|
self.stdout.write(self.style.WARNING("Notable Transmitters Created:"))
|
|
self.stdout.write("="*70)
|
|
for name in list(transmitters.keys())[:5]:
|
|
self.stdout.write(f" • {name}")
|
|
self.stdout.write(f" ... and {max(0, len(transmitters) - 5)} more")
|
|
self.stdout.write("="*70 + "\n")
|