# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-30 01:54
from __future__ import unicode_literals

from django.db import migrations, models

def forwards(apps, schema_editor):
    """Populate new count field"""
    Artist = apps.get_model("artists", "Artist")
    Comic = apps.get_model("comics", "Comic")
    artists = Artist.objects.all()
    for artist in artists:
        num_comics = Comic.objects.filter(artist_id=artist.id).count()
        artist.num_comics = num_comics
        artist.save()

def reverse(apps, schema_editor):
    return

class Migration(migrations.Migration):

    dependencies = [
        ('artists', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='artist',
            name='num_comics',
            field=models.IntegerField(default=0),
        ),
        migrations.RunPython(forwards, reverse),
    ]
