Skip to content

Commit

Permalink
fix: šŸ› Fix the imports for models to use apps instead of direct imporā€¦
Browse files Browse the repository at this point in the history
ā€¦t to fix install bug.
  • Loading branch information
jdrew82 committed Nov 6, 2024
1 parent d3f5a7a commit 3c25c3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/411.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed imports in CustomFields migration that was causing installation issues.
16 changes: 12 additions & 4 deletions nautobot_ssot/migrations/0007_replace_dashed_custom_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from django.db import migrations
from nautobot.dcim.models import Device, DeviceType, Interface, Location, Manufacturer
from nautobot.extras.models import Role
from nautobot.ipam.models import VLAN, IPAddress

CF_KEY_CHANGE_MAP = {
"ssot_synced_to_servicenow": "ssot-synced-to-servicenow",
Expand All @@ -12,6 +9,7 @@


def replace_dashed_custom_fields(apps, schema_editor):
"""Replace dashes in CustomField keys with underscore."""
CustomField = apps.get_model("extras", "customfield")

for new_key, old_key in CF_KEY_CHANGE_MAP.items():
Expand All @@ -23,7 +21,17 @@ def replace_dashed_custom_fields(apps, schema_editor):
custom_field.key = new_key
custom_field.save()

for model in [Device, DeviceType, Interface, Manufacturer, Location, VLAN, Role, IPAddress]:
for app, model in [
("dcim", "Device"),
("dcim", "DeviceType"),
("dcim", "Interface"),
("dcim", "Manufacturer"),
("dcim", "Location"),
("ipam", "VLAN"),
("extras", "Role"),
("ipam", "IPAddress"),
]:
model = apps.get_model(app, model)
cf_list = []
for instance in model.objects.all():
for new_cf, old_cf in CF_KEY_CHANGE_MAP.items():
Expand Down

0 comments on commit 3c25c3a

Please sign in to comment.