site_tps/settings/management/commands/create_admin.py
2018-03-02 11:51:42 +01:00

16 lines
881 B
Python

from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import Group, Permission
class Command(BaseCommand):
help = 'Creates admin group'
def handle(self, *args, **options):
admins,_ = Group.objects.get_or_create(name='admins')
admins.permissions.add(Permission.objects.get(codename="change_sitesettings"))
admins.permissions.add(Permission.objects.get(codename="add_schoolprofile"))
admins.permissions.add(Permission.objects.get(codename="delete_schoolprofile"))
admins.permissions.add(Permission.objects.get(codename="add_category"))
admins.permissions.add(Permission.objects.get(codename="delete_category"))
admins.permissions.add(Permission.objects.get(codename="change_category"))
admins.save()
self.stdout.write(self.style.SUCCESS('Admins created.'))