0003_auto_20151202_1539.py 1.07 KB
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.db import migrations, models

from common.util import no_history


def osc_commonness(apps, schema_editor):
    no_history()
    Lexeme = apps.get_model('dictionary', 'Lexeme')
    Classification = apps.get_model('dictionary', 'Classification')
    LexemeCV = apps.get_model('dictionary', 'LexemeCV')

    try:
        commonness = Classification.objects.get(name='pospolitość')
        commonness.parts_of_speech.add('osc')

        common_name = commonness.values.get(label__contains='pospolita')
        for osc in Lexeme.objects.filter(part_of_speech='osc'):
            LexemeCV.objects.get_or_create(lexeme=osc, classification_value=common_name)
    except ObjectDoesNotExist:
        pass
    except MultipleObjectsReturned:
        pass


class Migration(migrations.Migration):

    dependencies = [
        ('dictionary', '0002_auto_20151125_1201'),
    ]

    operations = [
        migrations.RunPython(osc_commonness),
    ]