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.'))