Skip to content

Fix "custom_fields" and "custom_field_groups" attr names on CO edit form #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{# Render all fields grouped by group_name #}
<div class="field-group mb-5">
{% for group, fields in form.custom_field_groups.items %}
{% for group, fields in form.custom_object_type_field_groups.items %}
{% if group %}
<div class="row">
<h3 class="col-9 offset-3 mb-3 h4">{{ group }}</h3>
Expand Down
16 changes: 8 additions & 8 deletions netbox_custom_objects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ def get_form(self, model):
"Meta": meta,
"__module__": "database.forms",
"_errors": None,
"custom_fields": {},
"custom_field_groups": {},
"custom_object_type_fields": {},
"custom_object_type_field_groups": {},
}

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

# Annotate the field in the list of CustomField form fields
attrs["custom_fields"][field_name] = field
attrs["custom_object_type_fields"][field_name] = field

# Group fields by group_name (similar to NetBox custom fields)
group_name = field.group_name or None # Use None for ungrouped fields
if group_name not in attrs["custom_field_groups"]:
attrs["custom_field_groups"][group_name] = []
attrs["custom_field_groups"][group_name].append(field_name)
if group_name not in attrs["custom_object_type_field_groups"]:
attrs["custom_object_type_field_groups"][group_name] = []
attrs["custom_object_type_field_groups"][group_name].append(field_name)

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

attrs["__init__"] = custom_init

Expand Down