Création automatique du group admin
This commit is contained in:
parent
d8bc39bbd2
commit
4e514471f1
3 changed files with 16 additions and 0 deletions
0
settings/management/__init__.py
Normal file
0
settings/management/__init__.py
Normal file
0
settings/management/commands/__init__.py
Normal file
0
settings/management/commands/__init__.py
Normal file
16
settings/management/commands/create_admin.py
Normal file
16
settings/management/commands/create_admin.py
Normal 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.'))
|
Loading…
Reference in a new issue