Skip to content

Commit 98c41e0

Browse files
committed
Use skip_object_fields on multi-object fields too
1 parent 12bc716 commit 98c41e0

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

netbox_custom_objects/field_types.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def get_form_field(self, field, for_csv_import=False, **kwargs):
717717
"model", ""
718718
)
719719
custom_object_type = CustomObjectType.objects.get(pk=custom_object_type_id)
720-
model = custom_object_type.get_model()
720+
model = custom_object_type.get_model(skip_object_fields=True)
721721
else:
722722
# This is a regular NetBox model
723723
model = content_type.model_class()
@@ -755,9 +755,13 @@ def get_table_column_field(self, field, **kwargs):
755755

756756
def get_serializer_field(self, field, **kwargs):
757757
related_model_class = field.related_object_type.model_class()
758-
if not related_model_class:
759-
raise NotImplementedError("Custom object serializers not implemented")
760-
serializer = get_serializer_for_model(related_model_class)
758+
if related_model_class._meta.app_label == APP_LABEL:
759+
from netbox_custom_objects.api.serializers import get_serializer_class
760+
serializer = get_serializer_class(related_model_class, skip_object_fields=True)
761+
# if not related_model_class:
762+
# raise NotImplementedError("Custom object serializers not implemented")
763+
else:
764+
serializer = get_serializer_for_model(related_model_class)
761765
return serializer(required=field.required, nested=True, many=True)
762766

763767
def after_model_generation(self, instance, model, field_name):

netbox_custom_objects/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,11 @@ def _fetch_and_generate_field_attrs(
335335
fields = list(fields) + [field for field in fields_query]
336336

337337
for field in fields:
338-
field_type = FIELD_TYPE_CLASS[field.type]()
339338
if skip_object_fields:
340339
if field.type in [CustomFieldTypeChoices.TYPE_OBJECT, CustomFieldTypeChoices.TYPE_MULTIOBJECT]:
341340
continue
342341

342+
field_type = FIELD_TYPE_CLASS[field.type]()
343343
field_name = field.name
344344

345345
field_attrs["_field_objects"][field.id] = {

0 commit comments

Comments
 (0)