0022_auto_20160226_1358.py
1.19 KB
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from accounts.util import bot_history
def ndk_pact(apps, schema_editor):
bot_history()
Lexeme = apps.get_model('dictionary', 'Lexeme')
LexemeAttribute = apps.get_model('dictionary', 'LexemeAttribute')
LexemeAttributeValue = apps.get_model('dictionary', 'LexemeAttributeValue')
LexemeAV = apps.get_model('dictionary', 'LexemeAV')
aspect = LexemeAttribute.objects.get(name='aspekt')
ndk = LexemeAttributeValue.objects.get(value='ndk')
other_aspects = list(aspect.values.exclude(value='ndk'))
pact_to_change = list(Lexeme.objects.filter(
part_of_speech_id='pact', lexemeattributevalue__in=other_aspects))
LexemeAV.objects.filter(
lexeme__in=pact_to_change, attribute_value__in=other_aspects).delete()
lavs = [LexemeAV(lexeme=pact, attribute_value=ndk)
for pact in pact_to_change]
LexemeAV.objects.bulk_create(lavs, batch_size=512)
class Migration(migrations.Migration):
dependencies = [
('dictionary', '0021_auto_20160115_1328'),
]
operations = [
migrations.RunPython(ndk_pact, lambda x, y: None),
]