-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43d90a5
commit ce58974
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
from django.db import migrations | ||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('backend', '0003_auto_20200605_0041'), | ||
] | ||
|
||
def generate_superuser(apps, schema_editor): | ||
from django.contrib.auth.models import User | ||
|
||
SU_NAME = 'admin' | ||
|
||
try: | ||
User.objects.get(username=SU_NAME) | ||
except User.DoesNotExist: | ||
SU_EMAIL = 'admin@example.com' | ||
SU_PASSWORD = 'admin' | ||
superuser = User.objects.create_superuser( | ||
username=SU_NAME, | ||
email=SU_EMAIL, | ||
password=SU_PASSWORD) | ||
superuser.is_superuser = True | ||
superuser.is_staff = True | ||
superuser.save() | ||
|
||
operations = [ | ||
migrations.RunPython(generate_superuser), | ||
] |