Skip to content

Commit 5e16cb7

Browse files
authored
Fix "custom_fields" and "custom_field_groups" attr names on CO edit form to avoid spuriously running custom_field handling code (#122)
1 parent 446240d commit 5e16cb7

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

netbox_custom_objects/templates/netbox_custom_objects/customobject_edit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
{# Render all fields grouped by group_name #}
2222
<div class="field-group mb-5">
23-
{% for group, fields in form.custom_field_groups.items %}
23+
{% for group, fields in form.custom_object_type_field_groups.items %}
2424
{% if group %}
2525
<div class="row">
2626
<h3 class="col-9 offset-3 mb-3 h4">{{ group }}</h3>

netbox_custom_objects/views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,8 @@ def get_form(self, model):
368368
"Meta": meta,
369369
"__module__": "database.forms",
370370
"_errors": None,
371-
"custom_fields": {},
372-
"custom_field_groups": {},
371+
"custom_object_type_fields": {},
372+
"custom_object_type_field_groups": {},
373373
}
374374

375375
for field in self.object.custom_object_type.fields.all().order_by('group_name', 'weight', 'name'):
@@ -379,13 +379,13 @@ def get_form(self, model):
379379
attrs[field_name] = field_type.get_annotated_form_field(field)
380380

381381
# Annotate the field in the list of CustomField form fields
382-
attrs["custom_fields"][field_name] = field
382+
attrs["custom_object_type_fields"][field_name] = field
383383

384384
# Group fields by group_name (similar to NetBox custom fields)
385385
group_name = field.group_name or None # Use None for ungrouped fields
386-
if group_name not in attrs["custom_field_groups"]:
387-
attrs["custom_field_groups"][group_name] = []
388-
attrs["custom_field_groups"][group_name].append(field_name)
386+
if group_name not in attrs["custom_object_type_field_groups"]:
387+
attrs["custom_object_type_field_groups"][group_name] = []
388+
attrs["custom_object_type_field_groups"][group_name].append(field_name)
389389

390390
except NotImplementedError:
391391
print(f"get_form: {field.name} field is not supported")
@@ -394,8 +394,8 @@ def get_form(self, model):
394394
def custom_init(self, *args, **kwargs):
395395
super(form_class, self).__init__(*args, **kwargs)
396396
# Set the grouping info as instance attributes from the outer scope
397-
self.custom_fields = attrs["custom_fields"]
398-
self.custom_field_groups = attrs["custom_field_groups"]
397+
self.custom_object_type_fields = attrs["custom_object_type_fields"]
398+
self.custom_object_type_field_groups = attrs["custom_object_type_field_groups"]
399399

400400
attrs["__init__"] = custom_init
401401

0 commit comments

Comments
 (0)