2020-05-07 10:45:06 +00:00
|
|
|
from django.core.management.base import BaseCommand
|
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
import sys
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = 'Give Admin rights to existing user'
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument('username', type=str)
|
2020-06-21 12:44:55 +00:00
|
|
|
parser.add_argument('--superuser', action='store_true')
|
2020-05-07 10:45:06 +00:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
user = get_user_model().objects.get(username=options['username'])
|
|
|
|
user.is_staff = True
|
2020-06-21 12:44:55 +00:00
|
|
|
|
|
|
|
if options['superuser']:
|
|
|
|
user.is_superuser = True
|
|
|
|
|
2020-05-07 10:45:06 +00:00
|
|
|
user.save()
|
|
|
|
|
2020-06-21 12:44:55 +00:00
|
|
|
print(f"{user.username} is now admin (superuser={user.is_superuser})")
|