Handle all associations

This commit is contained in:
Aleksandar Radunovic
2018-10-16 11:05:28 +02:00
parent 6cc4c67387
commit b53e886f8f
8 changed files with 156 additions and 65 deletions

View File

@@ -7,14 +7,16 @@ with open('/opt/netbox/initializers/device_roles.yml', 'r') as stream:
device_roles = yaml.load(stream)
if device_roles is not None:
for device_role_params in device_roles:
color = device_role_params.pop('color')
for params in device_roles:
for color_tpl in COLOR_CHOICES:
if color in color_tpl:
device_role_params['color'] = color_tpl[0]
if 'color' in params:
color = params.pop('color')
device_role, created = DeviceRole.objects.get_or_create(**device_role_params)
for color_tpl in COLOR_CHOICES:
if color in color_tpl:
params['color'] = color_tpl[0]
device_role, created = DeviceRole.objects.get_or_create(**params)
if created:
print("Created device role", device_role.name)