# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-08-29 13:08
from __future__ import unicode_literals

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


def runfwd(app, schema_editor):
    EventSettingsStore = app.get_model('pretixbase', 'Event_SettingsStore')
    AppConfiguration = app.get_model('pretixdroid', 'AppConfiguration')

    for setting in EventSettingsStore.objects.filter(key='pretixdroid_key'):
        AppConfiguration.objects.create(
            event=setting.object,
            key=setting.value,
            all_items=True
        )
        setting.delete()


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('pretixbase', '0074_auto_20170825_1258'),
        ('pretixdroid', '0002_auto_20161208_1644'),
    ]

    operations = [
        migrations.CreateModel(
            name='AppConfiguration',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('key', models.CharField(db_index=True, max_length=190)),
                ('all_items', models.BooleanField(default=True)),
                ('allow_search', models.BooleanField(default=True)),
                ('show_info', models.BooleanField(default=True)),
                ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='pretixbase.Event')),
                ('items', models.ManyToManyField(blank=True, to='pretixbase.Item')),
                ('subevent', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='pretixbase.SubEvent')),
            ],
        ),
        migrations.RunPython(
            runfwd, migrations.RunPython.noop
        )
    ]
