0062_auto_20171231_0056.py 1.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
# -*- 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),
    ]