Création automatique du group admin

This commit is contained in:
Klafyvel 2018-03-02 11:51:42 +01:00
parent d8bc39bbd2
commit 4e514471f1
3 changed files with 16 additions and 0 deletions

View file

View file

View file

@ -0,0 +1,16 @@
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.'))