# -*- coding: utf-8 -*-
# Generated by Django 1.10.2 on 2017-06-02 21:04
from __future__ import unicode_literals

from django.db import migrations


def add_phaselogs_to_old_tasks(apps, schema_editor):
    Task = apps.get_model('tasks', 'Task')
    TaskStatusLog = apps.get_model('tasks', 'TaskStatusLog')

    for task in Task.objects.filter(taskstatuslog__isnull=True):
        log = TaskStatusLog.objects.create(task=task, status=task.status, start=task.deadline)
        log.save()


def dummy(apps, schema_editor):
    pass


class Migration(migrations.Migration):

    dependencies = [
        ('tasks', '0023_merge_20170519_1012'),
    ]

    operations = [
        migrations.RunPython(add_phaselogs_to_old_tasks, dummy),
    ]

Fix old tasks for stats too
Fix old tasks for stats too
