# -*- coding: utf-8 -*-
# Generated by Django 1.11.9 on 2018-04-04 14:57
from __future__ import unicode_literals

from django.db import migrations


def load_articles(apps, schema_editor):
    Article = apps.get_model('articles', 'Article')
    OldArticle = apps.get_model('aldryn_newsblog', 'Article')
    Tag = apps.get_model('taggit', 'Tag')

    for old_article in OldArticle.objects.all():

        article = Article()

        article.created_by = old_article.owner
        article.publishing_date = old_article.publishing_date
        article.content = old_article.content
        article.featured_image = old_article.featured_image
        article.is_draft = True

        article.save()

        # copy categories
        for category in old_article.categories.all():
            article.categories.add(category)


def unload_articles(apps, schema_editor):
    Article = apps.get_model('articles', 'Article')

    Article.objects.all().delete()

class Migration(migrations.Migration):

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

    operations = [
        migrations.RunPython(load_articles, unload_articles),
    ]
