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.
 
 

34 lines
1.1 KiB

"""
Fix sects creation issue
"""
from django.core.management.base import BaseCommand
from apps.hadis.models import HadisSect
class Command(BaseCommand):
help = 'Fix sects creation'
def handle(self, **options):
self.stdout.write("Fixing sects...")
# Delete any problematic sects
HadisSect.objects.filter(sect_type='sunni').delete()
# Create sects with simple titles
sects_data = [
{'sect_type': 'shia', 'title': 'Shia', 'is_active': True, 'order': 1},
{'sect_type': 'sunni', 'title': 'Sunni', 'is_active': True, 'order': 2},
]
for data in sects_data:
sect, created = HadisSect.objects.get_or_create(
sect_type=data['sect_type'],
defaults=data
)
if created:
self.stdout.write(f"Created: {sect.sect_type} - {sect.title}")
else:
self.stdout.write(f"Exists: {sect.sect_type} - {sect.title}")
self.stdout.write(self.style.SUCCESS("Sects fixed!"))