0051_switchs_machine.py 1.21 KB
Newer Older
Gabriel Detraz's avatar
Gabriel Detraz committed
1 2 3 4 5 6 7 8 9 10 11
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-03-23 01:18
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    dependencies = [
Gabriel Detraz's avatar
Gabriel Detraz committed
12
        ('topologie', '0050_port_new_switch'),
Gabriel Detraz's avatar
Gabriel Detraz committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    ]

    def transfer_sw(apps, schema_editor):
        db_alias = schema_editor.connection.alias
        newswitch = apps.get_model("topologie", "NewSw")
        switch = apps.get_model("topologie", "Switch")
        machine =  apps.get_model("machines", "Machine")
        sw_list = switch.objects.using(db_alias).all()
        for sw in sw_list:
            new_sw = newswitch()
            new_sw.location = sw.location
            new_sw.number = sw.number
            new_sw.details = sw.details
            new_sw.stack = sw.stack
            new_sw.stack_member_id = sw.stack_member_id
            new_sw.model = sw.model
            new_sw.machine_ptr_id = sw.interface_ptr.machine.pk
            new_sw.__dict__.update(sw.interface_ptr.machine.__dict__) 
            new_sw.save()

    def untransfer_sw(apps, schema_editor):
        return


    operations = [
        migrations.RunPython(transfer_sw, untransfer_sw),
    ]