[Feature] Support polymorphic Object / MultiObject fields from netbox-custom-objects v0.5.0 #12
Description
Summary
netbox-custom-objects v0.5.0 introduced Polymorphic Object Fields, which let an Object or MultiObject Custom Object Type field reference instances of multiple content types through a generic foreign key. The feature is opt-in per field via the is_polymorphic flag, and the set of allowed targets is configured through the related_object_types M2M relation (see upstream issue netboxlabs/netbox-custom-objects#31).
netbox-custom-objects-tab does not appear to handle this case yet: when a Custom Object Type field is marked is_polymorphic=True, the tab does not show up on the referenced objects (or shows up inconsistently / empty), so polymorphic relationships are effectively invisible from the host object's detail view.
Expected behaviour
Given a Custom Object Type Foo with a polymorphic Object/MultiObject field target whose related_object_types includes, say, dcim.device and dcim.interface:
- Opening a Device that is referenced by one or more
Fooinstances should display the Custom Objects tab listing thoseFooinstances. - The same should happen on Interface detail views.
- MultiObject polymorphic fields should be handled the same way as single Object fields (each referenced object gets the tab).
- The reverse lookup should respect
related_nameif it has been set on the field (also new-ish upstream — #385).
Current behaviour
For non-polymorphic Object fields (single related_object_type) the tab works as expected. As soon as a field is switched to is_polymorphic=True, the tab does not render on objects of the allowed types.
Steps to reproduce
- Install
netbox-custom-objects≥ 0.5.0 andnetbox-custom-objects-tab. - Create a Custom Object Type, e.g.
Annotation. - Add an Object field
targetand set:is_polymorphic = Truerelated_object_types = [dcim.device, dcim.interface](or any 2+ core types)
- Create an
Annotationinstance pointing at an existing Device. - Open that Device → the Custom Objects tab is missing / empty.
- Switch the field back to non-polymorphic with
related_object_type = dcim.device→ the tab appears on the same Device.
Environment
- NetBox:
netbox-custom-objects: 0.5.0netbox-custom-objects-tab:- Python / Django:
Notes / pointers
- Detection logic probably needs to switch from filtering on
related_object_type_idto also querying the generic relation whenis_polymorphicis true, and iterating overrelated_object_types.all()to decide on which model classes the tab should be registered. - It may also be worth surfacing all polymorphic Custom Object Types that could point at the current object's content type, even if no instance currently does (matches the non-polymorphic behaviour today).
Activity
Add polymorphic Object/MultiObject field support + release 2.4.0 (closes