Add command to easily create admins

This commit is contained in:
Yingtong Li 2019-01-25 10:17:43 +11:00
parent 791027bae5
commit 44c8178af6
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
# Society Self-Service
# Copyright © 2018-2019 Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
class Command(BaseCommand):
help = 'Makes the user with the specified email an administrator'
def add_arguments(self, parser):
parser.add_argument('email')
def handle(self, *args, **options):
try:
user = User.objects.get(email=options['email'])
except User.DoesNotExist:
raise CommandError('No user with this email')
user.is_staff = True
user.is_superuser = True
user.save()
self.stdout.write(self.style.SUCCESS('Success'))