You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.3 KiB

# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2018-06-12 11:24
from __future__ import unicode_literals
import os
from json import load
from django.db import migrations, models
from django.core import serializers
TMP_FILE = '/tmp/djing_ip_field_devapp_migrate.json'
def device_backup_info(apps, _):
Device = apps.get_model('devapp', 'Device')
obs = Device.objects.all()
with open(TMP_FILE, 'w') as f:
serializers.serialize('json', obs, stream=f)
def device_restore_info_to_new_scheme(apps, _):
Device = apps.get_model('devapp', 'Device')
with open(TMP_FILE, 'r') as f:
for device in load(f):
Device.objects.filter(pk=device['pk']).update(ip_address=device['fields']['ip_address'])
if os.path.isfile(TMP_FILE):
os.remove(TMP_FILE)
class Migration(migrations.Migration):
dependencies = [
('devapp', '0004_device_extra_data'),
]
operations = [
migrations.RunPython(device_backup_info),
migrations.AlterField(
model_name='device',
name='ip_address',
field=models.GenericIPAddressField(blank=True, null=True, protocol='ipv4', verbose_name='Ip address'),
),
migrations.RunPython(device_restore_info_to_new_scheme)
]