# Generated by Django 2.2.8 on 2020-01-16 15:24

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

def update_event_type(apps, schema_editor):
    Event = apps.get_model("research", "Event")
    EventType = apps.get_model("research", "EventType")
    events = Event.objects.all()

    for event in events:
        try:
            type, created = EventType.objects.get_or_create(name=event.type, timeline=event.timeline)
            if created:
                type.save()
            event.new_type = type
            event.save()
        except:
            pass

class Migration(migrations.Migration):

    dependencies = [
        ('research', '0007_auto_20200110_1753'),
    ]

    operations = [
        migrations.AlterField(
            model_name='image',
            name='data',
            field=models.FileField(storage={'class': 'FileSystemStorage', 'kwargs': {'location': '/Users/anastasia/cap-timeline/timeline/db-files/images'}}, upload_to=''),
        ),
        migrations.CreateModel(
            name='EventType',
            fields=[
                ('name', models.CharField(blank=True, max_length=1000)),
                ('slug', autoslug.fields.AutoSlugField(editable=False, max_length=255, populate_from='name', primary_key=True, serialize=False, unique=True)),
                ('timeline', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, related_name='eventtypes', to='research.Meta')),
            ],
        ),
        migrations.AddField(
            model_name='event',
            name='new_type',
            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='events', to='research.EventType'),
        ),
        migrations.RunPython(update_event_type, migrations.RunPython.noop)
    ]
