-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create superuser only if it doesn't already exist
- Loading branch information
1 parent
5b84649
commit dec4de7
Showing
2 changed files
with
21 additions
and
1 deletion.
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,20 @@ | ||
import os | ||
import logging | ||
|
||
from django.contrib.auth import get_user_model | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
User = get_user_model() # get the currently active user model | ||
|
||
username = os.environ.get("DJANGO_SUPERUSER_USERNAME") | ||
user = User.objects.filter(username=username) | ||
|
||
if user.exists(): | ||
logger.debug("Skipping superuser creation since it already exists") | ||
else: | ||
email = os.environ.get("DJANGO_SUPERUSER_EMAIL") | ||
password = os.environ.get("DJANGO_SUPERUSER_PASSWORD") | ||
|
||
logger.debug("Creating superuser") | ||
User.objects.create_superuser(username, email, password) |
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