# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2019-06-19 15:52
from __future__ import unicode_literals

from django.db import migrations


def apply_categories_to_posts(apps, schema_editor):
    Post = apps.get_model('dashboard', 'Post')

    for post in Post.objects.all():
        post_needs_update = False
        for tag in post.tags.all():
            for category in tag.categories.all():
                post_needs_update = True
                post.categories.add(category)

        if post_needs_update:
            post.save()

class Migration(migrations.Migration):

    dependencies = [
        ('dashboard', '0071_populate-categories'),
    ]

    operations = [
        migrations.RunPython(apply_categories_to_posts)
    ]
