from django.db import migrations from django.conf import settings from django.contrib.auth.hashers import make_password def create_superuser(apps, schema_editor): User = apps.get_model('accounts', 'DepotUser') if not User.objects.filter(email=settings.ADMIN_USER_EMAIL).exists(): user = User.objects.create( email=settings.ADMIN_USER_EMAIL, username=settings.ADMIN_USER_NAME, is_staff=True, is_superuser=True, is_active=True, user_type='AD', password=make_password(settings.ADMIN_USER_PASSWORD) ) def reverse_superuser(apps, schema_editor): User = apps.get_model('accounts', 'DepotUser') User.objects.filter(email=settings.ADMIN_USER_EMAIL).delete() class Migration(migrations.Migration): dependencies = [ ('accounts', '0008_populate_permissions'), ] operations = [ migrations.RunPython(create_superuser, reverse_superuser), ]