# Generated by Django 2.0.1 on 2018-01-30 06:40
from django.db import (
    migrations, models
)
from django.utils import timezone


def convert_string_to_datetime(apps, schema_editor):
    Tweet = apps.get_model('trends', 'Tweet')
    for tweet in Tweet.objects.all():
        try:
            datetime_format = '%a %b %d %X %z %Y'
            tweet.published = timezone.datetime.strptime(tweet.created_at, datetime_format)
        except ValueError:
            tweet.published = timezone.now()
        tweet.save()


class Migration(migrations.Migration):

    dependencies = [
        ('trends', '0006_auto_20180124_1437'),
    ]

    operations = [
        migrations.AlterModelOptions(
            name='hashtag',
            options={'get_latest_by': 'created'},
        ),
        migrations.AlterModelOptions(
            name='trend',
            options={'get_latest_by': 'created'},
        ),
        migrations.AlterModelOptions(
            name='tweet',
            options={'get_latest_by': 'created'},
        ),
        migrations.AddField(
            model_name='tweet',
            name='published',
            field=models.DateTimeField(blank=True, null=True),
        ),
        migrations.RunPython(convert_string_to_datetime, migrations.RunPython.noop)
    ]
