# -*- coding: utf-8 -*- # Generated by Django 1.11.12 on 2018-08-13 23:05 from __future__ import unicode_literals from django.db import migrations def set_branch_layer(apps, schema_editor): LayerUpdate = apps.get_model('layerindex', 'LayerUpdate') for layerupdate in LayerUpdate.objects.all(): layerupdate.branch = layerupdate.layerbranch.branch layerupdate.layer = layerupdate.layerbranch.layer layerupdate.save() def set_layerbranch(apps, schema_editor): LayerUpdate = apps.get_model('layerindex', 'LayerUpdate') LayerBranch = apps.get_model('layerindex', 'LayerBranch') to_delete = [] for layerupdate in LayerUpdate.objects.all(): layerbranch = LayerBranch.objects.filter(layeritem=layerupdate.layer, branch=layerupdate.branch).first() if layerbranch: layerupdate.layerbranch = layerbranch layerupdate.save() else: # The whole point of splitting layerbranch -> layer,branch was to # be able to have records with no corresponding LayerBranch, so we # now have to delete any that don't when reversing to_delete.append(layerupdate.id) for luid in to_delete: LayerUpdate.objects.filter(id=luid).delete() class Migration(migrations.Migration): dependencies = [ ('layerindex', '0021_layerupdate_add_layer_branch'), ] operations = [ migrations.RunPython(set_branch_layer, reverse_code=set_layerbranch), ]