diff --git a/bds/migrations/0002_add_BDS_groups.py b/bds/migrations/0002_add_BDS_groups.py new file mode 100644 index 00000000..f0b4a75c --- /dev/null +++ b/bds/migrations/0002_add_BDS_groups.py @@ -0,0 +1,52 @@ +# -*- 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), + ] diff --git a/bds/models.py b/bds/models.py index ecfbb3db..da80dd77 100644 --- a/bds/models.py +++ b/bds/models.py @@ -55,3 +55,11 @@ class BdsProfile(models.Model): default='CASH', choices=PAYMENT_METHOD_CHOICES, max_length=6) + + class Meta: + verbose_name = "Profil BDS" + verbose_name_plural = "Profils BDS" + permissions = [ + ("member", "Is a BDS member"), + ("buro", "Is part of the BDS staff") + ]