Allow modifying the assigned component for InventoryItems in the UI #7343

Closed
opened 2025-12-29 20:22:08 +01:00 by adam · 1 comment
Owner

Originally created by @kkthxbye-code on GitHub (Dec 11, 2022).

Originally assigned to: @kkthxbye-code on GitHub.

NetBox version

v3.3.9

Feature type

Change to existing functionality

Proposed functionality

Currently it is possible to change the assigned component of an InventoryItem via. the API. It is however not possible to change the associated InventoryItem via. the UI. This means that the only way to create the association is by going to the component details view and clicking "Add Inventory Item". It is not possible to change the relationship afterwards and it is not possible to remove the relationship either.

A component field should be added to InventoryItem form to allow changing the associated component. The challenge is that the component field is a generic foreign key to any of the component types, so we need to figure out a slick way to present this to the user. We do it the following way for IP assignment currently:

image

However as there are currently 7 types of device components that support associating an InventoryItem, this might be a little much in the UI.

Use case

Changing the associated component might be useful adding the inventoryitem after the component has been added to the device. There might also be times where a component should be removed but the inventory item should stay. Similarly it might be useful to change the associated component, if an SFP is moved to another port for example.

Lastly it will allow the user to do in the UI what is already possible in the API.

Database changes

None

External dependencies

None

Originally created by @kkthxbye-code on GitHub (Dec 11, 2022). Originally assigned to: @kkthxbye-code on GitHub. ### NetBox version v3.3.9 ### Feature type Change to existing functionality ### Proposed functionality Currently it is possible to change the assigned component of an InventoryItem via. the API. It is however not possible to change the associated InventoryItem via. the UI. This means that the only way to create the association is by going to the component details view and clicking "Add Inventory Item". It is not possible to change the relationship afterwards and it is not possible to remove the relationship either. A component field should be added to InventoryItem form to allow changing the associated component. The challenge is that the component field is a generic foreign key to any of the component types, so we need to figure out a slick way to present this to the user. We do it the following way for IP assignment currently: ![image](https://user-images.githubusercontent.com/400797/206907026-3a7b9b81-4b2f-4f6a-b425-c144eb41a9ee.png) However as there are currently 7 types of device components that support associating an InventoryItem, this might be a little much in the UI. ### Use case Changing the associated component might be useful adding the inventoryitem after the component has been added to the device. There might also be times where a component should be removed but the inventory item should stay. Similarly it might be useful to change the associated component, if an SFP is moved to another port for example. Lastly it will allow the user to do in the UI what is already possible in the API. ### Database changes None ### External dependencies None
adam added the status: acceptedtype: feature labels 2025-12-29 20:22:08 +01:00
adam closed this issue 2025-12-29 20:22:08 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Dec 13, 2022):

I looked a little at this, and it doesn't seem like we have a good pattern for these cases (generic relations).

This is what we currently do for IP assignment:

860805ba82/netbox/templates/ipam/ipaddress_edit.html (L32-L56)

860805ba82/netbox/ipam/forms/models.py (L414-L434)

860805ba82/netbox/ipam/forms/models.py (L451-L462)

You have any ideas here @jeremystretch - I can try to replicate this functionality for the inventoryitem -> component relationship, but it doesn't seem very clean. However I'm not sure how much we're using/will be using generic relationships in the future, so it might not be worth it to spend a bunch of time on a generic solution.

@kkthxbye-code commented on GitHub (Dec 13, 2022): I looked a little at this, and it doesn't seem like we have a good pattern for these cases (generic relations). This is what we currently do for IP assignment: https://github.com/netbox-community/netbox/blob/860805ba8245f5d5a4401dca041b21678b55f060/netbox/templates/ipam/ipaddress_edit.html#L32-L56 https://github.com/netbox-community/netbox/blob/860805ba8245f5d5a4401dca041b21678b55f060/netbox/ipam/forms/models.py#L414-L434 https://github.com/netbox-community/netbox/blob/860805ba8245f5d5a4401dca041b21678b55f060/netbox/ipam/forms/models.py#L451-L462 You have any ideas here @jeremystretch - I can try to replicate this functionality for the inventoryitem -> component relationship, but it doesn't seem very clean. However I'm not sure how much we're using/will be using generic relationships in the future, so it might not be worth it to spend a bunch of time on a generic solution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7343