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.
45 lines
1.7 KiB
45 lines
1.7 KiB
from django.core.management.base import BaseCommand
|
|
from apps.hadis.models import HadisSect
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Test sects creation'
|
|
|
|
def handle(self, **options):
|
|
_ = options # Suppress unused variable warning
|
|
self.stdout.write("Testing sects creation...")
|
|
|
|
try:
|
|
# Check existing sects
|
|
existing_sects = HadisSect.objects.all()
|
|
self.stdout.write(f"Found {existing_sects.count()} existing sects:")
|
|
for sect in existing_sects:
|
|
self.stdout.write(f" - {sect.sect_type}: {sect.title}")
|
|
|
|
# Try to create sunni sect using direct create
|
|
self.stdout.write("Attempting to create sunni sect...")
|
|
|
|
# Check if sunni exists
|
|
try:
|
|
sunni_sect = HadisSect.objects.get(sect_type='sunni')
|
|
self.stdout.write(f"Sunni sect already exists: {sunni_sect.title}")
|
|
except HadisSect.DoesNotExist:
|
|
# Create sunni sect
|
|
self.stdout.write("Creating new sunni sect...")
|
|
sunni_sect = HadisSect(
|
|
sect_type='sunni',
|
|
title='Сунниты',
|
|
is_active=True,
|
|
order=2
|
|
)
|
|
sunni_sect.save()
|
|
self.stdout.write(self.style.SUCCESS(f"Created sunni sect: {sunni_sect.title}"))
|
|
|
|
# Final count
|
|
final_count = HadisSect.objects.count()
|
|
self.stdout.write(f"Total sects after operation: {final_count}")
|
|
|
|
except Exception as e:
|
|
self.stdout.write(self.style.ERROR(f"Error: {str(e)}"))
|
|
import traceback
|
|
self.stdout.write(self.style.ERROR(traceback.format_exc()))
|