You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
depot_django/accounts/migrations/0009_create_superuser.py

29 lines
978 B
Python

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),
]