52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
from django.contrib.auth.models import Group, Permission
|
|
from django.db import migrations
|
|
|
|
|
|
def create_groups(apps, schema_editor):
|
|
from django.contrib.auth.management import create_permissions
|
|
|
|
apps.models_module = True
|
|
create_permissions(apps, verbosity=0)
|
|
apps.models_module = None
|
|
|
|
memberp = Permission.objects.get(
|
|
codename="member",
|
|
content_type__app_label="bds"
|
|
)
|
|
burop = Permission.objects.get(
|
|
codename="buro",
|
|
content_type__app_label="bds"
|
|
)
|
|
|
|
# Creates the groups for BDS members and staff
|
|
member = Group.objects.create(name="bds_members")
|
|
buro = Group.objects.create(name="bds_buro")
|
|
|
|
# Associates the permissions to the respective groups
|
|
member.permissions = [memberp]
|
|
buro.permissions = [memberp, burop]
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('bds', '0001_initial'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AlterModelOptions(
|
|
name='bdsprofile',
|
|
options={
|
|
'permissions': [
|
|
('member', 'Is a BDS member'),
|
|
('buro', 'Is part of the BDS staff')
|
|
],
|
|
'verbose_name': 'Profil BDS',
|
|
'verbose_name_plural': 'Profils BDS'
|
|
},
|
|
),
|
|
migrations.RunPython(create_groups, migrations.RunPython.noop),
|
|
]
|