0001_initial.py 2.93 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
# Generated by Django 1.11.5 on 2017-10-25 17:25
3 4 5
from __future__ import unicode_literals

from django.conf import settings
6 7 8
from django.db import migrations, models
import django.db.models.deletion
from django.apps import apps as django_apps
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
def guardian_post_migrate_signal(apps, schema_editor):

    # We need to emit a post-migrate signal so that django.contrib.auth
    # will create the permission objects corresponding to the new
    # GroupObjectPermission and UserObjectPermission models that were
    # created by django-guardian. This is definitely not the nicest
    # way of doing things, but it's what we are stuck with for now.
    print("\n\nManually emitting post-migrate signal for guardian:")
    guardian_config = django_apps.get_app_config('guardian')
    models.signals.post_migrate.send(
        sender=guardian_config,
        app_config=guardian_config,
        verbosity=2,
        interactive=False,
        using=schema_editor.connection.alias,
    )
26 27 28

class Migration(migrations.Migration):

29 30
    initial = True

31
    dependencies = [
32
        ('auth', '0007_auto_20150708_1134'),
33
        ('contenttypes', '0002_remove_content_type_name'),
34 35 36 37 38 39
    ]

    operations = [
        migrations.CreateModel(
            name='GroupObjectPermission',
            fields=[
40
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
41
                ('object_pk', models.CharField(max_length=255, verbose_name='object ID')),
42 43 44
                ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
                ('group', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Group')),
                ('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Permission')),
45 46 47 48 49
            ],
        ),
        migrations.CreateModel(
            name='UserObjectPermission',
            fields=[
50
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
51
                ('object_pk', models.CharField(max_length=255, verbose_name='object ID')),
52 53 54
                ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
                ('permission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auth.Permission')),
                ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
55 56 57 58 59 60 61 62 63 64
            ],
        ),
        migrations.AlterUniqueTogether(
            name='userobjectpermission',
            unique_together=set([('user', 'permission', 'object_pk')]),
        ),
        migrations.AlterUniqueTogether(
            name='groupobjectpermission',
            unique_together=set([('group', 'permission', 'object_pk')]),
        ),
65
        migrations.RunPython(guardian_post_migrate_signal, reverse_code=None),
66
    ]