-
Notifications
You must be signed in to change notification settings - Fork 102
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
Showing
6 changed files
with
138 additions
and
95 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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.contrib.auth import get_user_model | ||
from django.core.management.base import BaseCommand | ||
|
||
User = get_user_model() | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Updates the superuser' | ||
help = "Updates the superuser" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument('--username', required=True) | ||
parser.add_argument('--email', required=True) | ||
parser.add_argument("--username", required=True) | ||
parser.add_argument("--email", required=True) | ||
|
||
def handle(self, *args, **options): | ||
username = options['username'] | ||
email = options['email'] | ||
username = options["username"] | ||
email = options["email"] | ||
|
||
try: | ||
user = User.objects.get(username=username) | ||
user.email = email | ||
user.save() | ||
self.stdout.write(self.style.SUCCESS(f'Superuser {username} updated successfully')) | ||
self.stdout.write( | ||
self.style.SUCCESS(f"Superuser {username} updated successfully") | ||
) | ||
except User.DoesNotExist: | ||
User.objects.create_superuser(username=username, email=email) | ||
self.stdout.write(self.style.SUCCESS(f'Superuser {username} created successfully')) | ||
self.stdout.write( | ||
self.style.SUCCESS(f"Superuser {username} created successfully") | ||
) |
Oops, something went wrong.