# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-12-04 10:36
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):
    def add_created_modified_date(apps, schema_editor):
        Course = apps.get_model('courses', 'Course')
        courses = Course.objects.all()

        for course in courses:
            course.created = course.history.earliest().history_date
            course.modified = course.history.latest().history_date
            course.save()

    dependencies = [
        ('courses', '0005_auto_20170525_0131'),
    ]

    operations = [
        migrations.AddField(
            model_name='course',
            name='created',
            field=models.DateTimeField(auto_now_add=True, null=True),
        ),
        migrations.AddField(
            model_name='course',
            name='modified',
            field=models.DateTimeField(auto_now=True, null=True),
        ),
        migrations.AddField(
            model_name='historicalcourse',
            name='created',
            field=models.DateTimeField(blank=True, editable=False, null=True),
        ),
        migrations.AddField(
            model_name='historicalcourse',
            name='modified',
            field=models.DateTimeField(blank=True, editable=False, null=True),
        ),
        migrations.RunPython(add_created_modified_date, migrations.RunPython.noop),
    ]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-12-04 10:36
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):
    def add_created_modified_date(apps, schema_editor):
        Course = apps.get_model('courses', 'Course')
        HistoricalCourse = apps.get_model('courses', 'historicalcourse')
        courses = Course.objects.all()

        for course in courses:
            history = HistoricalCourse.objects.filter(id=course.id)
            course.created = history.earliest().history_date
            course.modified = history.latest().history_date
            course.save()

    dependencies = [
        ('courses', '0005_auto_20170525_0131'),
    ]

    operations = [
        migrations.AddField(
            model_name='course',
            name='created',
            field=models.DateTimeField(auto_now_add=True, null=True),
        ),
        migrations.AddField(
            model_name='course',
            name='modified',
            field=models.DateTimeField(auto_now=True, null=True),
        ),
        migrations.AddField(
            model_name='historicalcourse',
            name='created',
            field=models.DateTimeField(blank=True, editable=False, null=True),
        ),
        migrations.AddField(
            model_name='historicalcourse',
            name='modified',
            field=models.DateTimeField(blank=True, editable=False, null=True),
        ),
        migrations.RunPython(add_created_modified_date, migrations.RunPython.noop),
    ]

Fix migration issue Fixed 'Course' object has no attribute 'history' issue in the migration