Fixed content type assignment within migration

This commit is contained in:
Jeremy Stretch 2018-10-19 10:38:15 -04:00
parent ea5121ffe1
commit d908dffab7

View File

@ -9,13 +9,14 @@ def console_connections_to_cables(apps, schema_editor):
""" """
Copy all existing console connections as Cables Copy all existing console connections as Cables
""" """
ContentType = apps.get_model('contenttypes', 'ContentType')
ConsolePort = apps.get_model('dcim', 'ConsolePort') ConsolePort = apps.get_model('dcim', 'ConsolePort')
ConsoleServerPort = apps.get_model('dcim', 'ConsoleServerPort')
Cable = apps.get_model('dcim', 'Cable') Cable = apps.get_model('dcim', 'Cable')
# Load content types # Load content types
ContentType = apps.get_model('contenttypes', 'ContentType') consoleport_type = ContentType.objects.get_for_model(ConsolePort)
consoleport_type = ContentType.objects.get(app_label='dcim', model='consoleport') consoleserverport_type = ContentType.objects.get_for_model(ConsoleServerPort)
consoleserverport_type = ContentType.objects.get(app_label='dcim', model='consoleserverport')
# Create a new Cable instance from each console connection # Create a new Cable instance from each console connection
for consoleport in ConsolePort.objects.filter(cs_port__isnull=False): for consoleport in ConsolePort.objects.filter(cs_port__isnull=False):
@ -33,13 +34,14 @@ def power_connections_to_cables(apps, schema_editor):
""" """
Copy all existing power connections as Cables Copy all existing power connections as Cables
""" """
ContentType = apps.get_model('contenttypes', 'ContentType')
PowerPort = apps.get_model('dcim', 'PowerPort') PowerPort = apps.get_model('dcim', 'PowerPort')
PowerOutlet = apps.get_model('dcim', 'PowerOutlet')
Cable = apps.get_model('dcim', 'Cable') Cable = apps.get_model('dcim', 'Cable')
# Load content types # Load content types
ContentType = apps.get_model('contenttypes', 'ContentType') powerport_type = ContentType.objects.get_for_model(PowerPort)
powerport_type = ContentType.objects.get(app_label='dcim', model='powerport') poweroutlet_type = ContentType.objects.get_for_model(PowerOutlet)
poweroutlet_type = ContentType.objects.get(app_label='dcim', model='poweroutlet')
# Create a new Cable instance from each power connection # Create a new Cable instance from each power connection
for powerport in PowerPort.objects.filter(power_outlet__isnull=False): for powerport in PowerPort.objects.filter(power_outlet__isnull=False):
@ -57,12 +59,13 @@ def interface_connections_to_cables(apps, schema_editor):
""" """
Copy all InterfaceConnections as Cables Copy all InterfaceConnections as Cables
""" """
ContentType = apps.get_model('contenttypes', 'ContentType')
Interface = apps.get_model('dcim', 'Interface')
InterfaceConnection = apps.get_model('dcim', 'InterfaceConnection') InterfaceConnection = apps.get_model('dcim', 'InterfaceConnection')
Cable = apps.get_model('dcim', 'Cable') Cable = apps.get_model('dcim', 'Cable')
# Load content types # Load content types
ContentType = apps.get_model('contenttypes', 'ContentType') interface_type = ContentType.objects.get_for_model(Interface)
interface_type = ContentType.objects.get(app_label='dcim', model='interface')
# Create a new Cable instance from each InterfaceConnection # Create a new Cable instance from each InterfaceConnection
for conn in InterfaceConnection.objects.all(): for conn in InterfaceConnection.objects.all():