site_tps/settings/management/commands/create_admin.py

17 lines
881 B
Python
Raw Normal View History

2018-03-02 10:51:42 +00:00
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.'))