Enhance make-admin to allow making superuser

This commit is contained in:
Nico Schottelius 2020-06-21 14:44:55 +02:00
parent 1e68539ed8
commit 424ceafbb8

View file

@ -7,10 +7,15 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('username', type=str)
parser.add_argument('--superuser', action='store_true')
def handle(self, *args, **options):
user = get_user_model().objects.get(username=options['username'])
user.is_staff = True
if options['superuser']:
user.is_superuser = True
user.save()
print("{} is now admin.".format(user.username))
print(f"{user.username} is now admin (superuser={user.is_superuser})")