gestioCOF/bds/migrations/0002_bds_group.py
Ludovic Stephan b3e7b59903
Migrations
Une migration pour les modèles, et une pour créer le groupe du Burô du
BDS
2019-10-15 21:51:40 +02:00

30 lines
945 B
Python

# Generated by Django 2.2 on 2019-07-17 14:56
from django.contrib.auth.management import create_permissions
from django.db import migrations
from django.db.models import Q
def create_bds_buro_group(apps, schema_editor):
for app_config in apps.get_app_configs():
create_permissions(app_config, apps=apps, verbosity=0)
Group = apps.get_model("auth", "Group")
Permission = apps.get_model("auth", "Permission")
group, created = Group.objects.get_or_create(name="Burô du BDS")
if created:
perms = Permission.objects.filter(
Q(content_type__app_label="bds")
| Q(content_type__app_label="auth") & Q(content_type__model="user")
)
group.permissions.set(perms)
group.save()
class Migration(migrations.Migration):
dependencies = [("bds", "0001_initial")]
operations = [
migrations.RunPython(create_bds_buro_group, migrations.RunPython.noop)
]