# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2019-03-09 16:59
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion

from ..models.permission import upgrade_perms, downgrade_perms


class Migration(migrations.Migration):

    dependencies = [
        ('wechat_django', '0001_init'),
    ]

    operations = [
        migrations.CreateModel(
            name='UserTag',
            fields=[
                ('_id', models.AutoField(primary_key=True, serialize=False)),
                ('id', models.IntegerField(verbose_name='tag id')),
                ('name', models.CharField(max_length=30, verbose_name='tag name')),
                ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='created at')),
            ],
        ),
        migrations.AlterField(
            model_name='wechatapp',
            name='appsecret',
            field=models.CharField(blank=True, max_length=64, null=True, verbose_name='AppSecret'),
        ),
        migrations.AddField(
            model_name='usertag',
            name='app',
            field=models.ForeignKey(editable=False, on_delete=django.db.models.deletion.CASCADE, related_name='user_tags', to='wechat_django.WeChatApp'),
        ),
        migrations.AddField(
            model_name='usertag',
            name='users',
            field=models.ManyToManyField(related_name='tags', to='wechat_django.WeChatUser'),
        ),
        migrations.AlterUniqueTogether(
            name='usertag',
            unique_together=set([('app', 'name'), ('app', 'id')]),
        ),
    ]

    # 追加两个权限
    migrations.RunPython(
        lambda *args, **kwargs: upgrade_perms("usertag", "usertag_sync"),
        lambda *args, **kwargs: downgrade_perms("usertag", "usertag_sync"),
    )
