diff options
Diffstat (limited to 'store/migrations/0002_create_superuser.py')
| -rw-r--r-- | store/migrations/0002_create_superuser.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/store/migrations/0002_create_superuser.py b/store/migrations/0002_create_superuser.py new file mode 100644 index 0000000..4f322d6 --- /dev/null +++ b/store/migrations/0002_create_superuser.py @@ -0,0 +1,26 @@ +from django.db import migrations +import os + +def create_superuser(apps, schema_editor): + User = apps.get_model('store', 'User') + db_alias = schema_editor.connection.alias + + if not User.objects.using(db_alias).filter(username='admin').exists(): + User.objects.create_superuser( + username=os.environ.get('DJANGO_SUPERUSER_USERNAME', 'admin'), + email=os.environ.get('DJANGO_SUPERUSER_EMAIL', 'admin@example.com'), + password=os.environ.get('DJANGO_SUPERUSER_PASSWORD', 'admin'), + is_staff=True, + is_superuser=True, + roles=['user', 'admin'] + ) + +class Migration(migrations.Migration): + + dependencies = [ + ('store', '0001_initial'), + ] + + operations = [ + migrations.RunPython(create_superuser, migrations.RunPython.noop), + ] |
