# Generated by Django 2.2.7 on 2019-12-20 12:24

from django.db import migrations, models
import django.db.models.deletion


def fill_translations(apps, schemaeditor):
    Tag = apps.get_model('tag', 'Tag')
    TagCategory = apps.get_model('tag', 'TagCategory')
    SiteInterfaceDictionary = apps.get_model('translation', 'SiteInterfaceDictionary')

    for tag_category in TagCategory.objects.all():
        if tag_category.label:
            t = SiteInterfaceDictionary(text=tag_category.label)
            t.save()
            tag_category.translation = t
            tag_category.save()

    for tag in Tag.objects.all():
        if tag.label:
            t = SiteInterfaceDictionary(text=tag.label)
            t.save()
            tag.translation = t
            tag.save()


class Migration(migrations.Migration):

    dependencies = [
        ('translation', '0007_language_is_active'),
        ('tag', '0015_auto_20191118_1210'),
    ]

    operations = [
        migrations.AddField(
            model_name='tag',
            name='translation',
            field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tag', to='translation.SiteInterfaceDictionary', verbose_name='Translation'),
        ),
        migrations.AddField(
            model_name='tagcategory',
            name='translation',
            field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='tag_category', to='translation.SiteInterfaceDictionary', verbose_name='Translation'),
        ),
        migrations.RunPython(fill_translations, migrations.RunPython.noop)
    ]
