8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-20 10:23:12 +00:00
re2o/users/migrations/0062_auto_20171231_0056.py
Hugo Levy-Falk c4a104b3b6 I like my black.
Just ran black on the whoe repository. Fix #210.
2019-11-04 22:47:24 +01:00

50 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-12-30 23:56
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("auth", "0008_alter_user_username_max_length"),
("users", "0061_auto_20171230_2033"),
]
def create_groups(apps, schema_editor):
group = apps.get_model("auth", "Group")
listrights = apps.get_model("users", "ListRight")
db_alias = schema_editor.connection.alias
for gr in listrights.objects.using(db_alias).all():
grp = group()
grp.name = gr.unix_name
grp.save()
gr.group_ptr = grp
gr.save()
def delete_groups(apps, schema_editor):
group = apps.get_model("auth", "Group")
db_alias = schema_editor.connection.alias
group.objects.using(db_alias).all().delete()
operations = [
migrations.RenameField(
model_name="listright", old_name="listright", new_name="unix_name"
),
migrations.AddField(
model_name="listright",
name="group_ptr",
field=models.OneToOneField(
blank=True,
null=True,
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
serialize=False,
to="auth.Group",
),
preserve_default=False,
),
migrations.RunPython(create_groups, delete_groups),
]