# -*- coding: utf-8 -*-
# Generated by Django 1.11.13 on 2018-06-26 17:33
from __future__ import unicode_literals

from django.db import migrations, models
from for_runners.gpx import parse_gpx


def set_creator(apps, schema_editor):
    print("Set creator")
    GpxModel = apps.get_model('for_runners', 'gpxmodel')
    for track in GpxModel.objects.all():

        gpxpy_instance = parse_gpx(content=track.gpx)

        track.creator = gpxpy_instance.creator
        track.save()
        print(".", end="", flush=True)
    print()


class Migration(migrations.Migration):

    dependencies = [
        ('for_runners', '0004_auto_20180621_1948'),
    ]

    operations = [
        migrations.AddField(
            model_name='gpxmodel',
            name='creator',
            field=models.CharField(
                blank=True, help_text='Used device to create this track', max_length=511, null=True
            ),
        ),
        migrations.RunPython(set_creator, reverse_code=migrations.RunPython.noop),
    ]
