-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added create super user script and change main.yml
- Loading branch information
Showing
2 changed files
with
36 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
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,17 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.contrib.auth.models import User | ||
from decouple import config | ||
|
||
class Command(BaseCommand): | ||
help = 'Create a superuser' | ||
|
||
def handle(self, *args, **kwargs): | ||
username = config('DJANGO_SUPERUSER_USERNAME') | ||
email = config('DJANGO_SUPERUSER_EMAIL') | ||
password = config('DJANGO_SUPERUSER_PASSWORD') | ||
|
||
if User.objects.filter(username=username).exists(): | ||
self.stdout.write(self.style.WARNING('Superuser already exists.')) | ||
else: | ||
User.objects.create_superuser(username=username, email=email, password=password) | ||
self.stdout.write(self.style.SUCCESS('Superuser created successfully.')) |