47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
# Generated by Django 4.1.6 on 2023-02-24 15:03
|
|
|
|
from django.contrib.auth.management import create_permissions
|
|
from django.db import migrations, models
|
|
|
|
|
|
def apply_migration(apps, schema_editor):
|
|
# Create all permissions
|
|
for app_config in apps.get_app_configs():
|
|
app_config.models_module = True
|
|
create_permissions(app_config, verbosity=0)
|
|
app_config.models_module = None
|
|
Group = apps.get_model("auth", "Group")
|
|
grp, _ = Group.objects.get_or_create(name="hackens_member")
|
|
grp.save()
|
|
|
|
Permission = apps.get_model("auth", "Permission")
|
|
ContentType = apps.get_model("contenttypes", "ContentType")
|
|
|
|
BudgetGroup = apps.get_model("budget", "BudgetGroup")
|
|
BudgetLine = apps.get_model("budget", "BudgetLine")
|
|
|
|
content_type = ContentType.objects.get_for_model(BudgetGroup)
|
|
all_permissions = Permission.objects.filter(content_type=content_type)
|
|
grp.permissions.add(*all_permissions)
|
|
|
|
content_type = ContentType.objects.get_for_model(BudgetLine)
|
|
all_permissions = Permission.objects.filter(content_type=content_type)
|
|
grp.permissions.add(*all_permissions)
|
|
|
|
grp.save()
|
|
|
|
|
|
def revert_migration(apps, schema_editor):
|
|
Group = apps.get_model("auth", "Group")
|
|
Group.objects.filter(
|
|
name="hackens_member",
|
|
).delete()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
("budget", "0001_initial"),
|
|
]
|
|
|
|
operations = [migrations.RunPython(apply_migration, revert_migration)]
|