Skip to content

Commit

Permalink
Merge pull request #101 from matejv/object-type
Browse files Browse the repository at this point in the history
custom_field object_time renamed to related_object_type
  • Loading branch information
tobiasge authored Jun 7, 2024
2 parents 50d077d + aa4794d commit b3fb7c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 14 additions & 3 deletions src/netbox_initializers/initializers/custom_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,30 @@ def load_data(self):
if cf_details.get("is_cloneable", None) is not None:
custom_field.is_cloneable = cf_details["is_cloneable"]

# object_type should only be applied when type is object, multiobject
# object_type was renamed to related_object_type in netbox 4.0
if cf_details.get("object_type"):
print(
f"⚠️ Unable to create Custom Field '{cf_name}': please rename object_type "
+ "to related_object_type"
)
custom_field.delete()
continue

# related_object_type should only be applied when type is object, multiobject
if cf_details.get("related_object_type"):
if cf_details.get("type") not in (
"object",
"multiobject",
):
print(
f"⚠️ Unable to create Custom Field '{cf_name}': object_type is "
f"⚠️ Unable to create Custom Field '{cf_name}': related_object_type is "
+ "supported only for object and multiobject types"
)
custom_field.delete()
continue
custom_field.object_type = get_class_for_class_path(cf_details["object_type"])
custom_field.related_object_type = get_class_for_class_path(
cf_details["related_object_type"]
)

# validation_regex should only be applied when type is text, longtext, url
if cf_details.get("validation_regex"):
Expand Down
4 changes: 2 additions & 2 deletions src/netbox_initializers/initializers/yaml/custom_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
# filter_logic: loose
# on_objects:
# - dcim.models.Location
# object_type: ipam.models.IPAddress
# related_object_type: ipam.models.IPAddress
# object_field:
# type: object
# label: ASN
Expand All @@ -109,4 +109,4 @@
# filter_logic: loose
# on_objects:
# - dcim.models.Device
# object_type: ipam.models.ASN
# related_object_type: ipam.models.ASN

0 comments on commit b3fb7c7

Please sign in to comment.