# -*- coding: utf-8 -*-
# Generated by Django 1.9.4 on 2016-07-22 11:02
from __future__ import unicode_literals

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


def make_sort_names(apps, schema_editor):
    # We can't import the Venue model directly as it may be a newer
    # version than this migration expects. We use the historical version.

    Venue = apps.get_model("events", "Venue")

    for venue in Venue.objects.filter(sort_name=''):
        venue.sort_name = calculate_venue_sort_name(venue.name)

        venue.save()


class Migration(migrations.Migration):

    dependencies = [
        ('events', '0002_auto_20160719_1856'),
    ]

    operations = [
        migrations.AddField(
            model_name='venue',
            name='sort_name',
            field=models.CharField(default='', editable=False, max_length=50),
        ),
        migrations.RunPython(make_sort_names, lambda x, y: None),
    ]
