Only show valid platforms when editing a device #3101

Closed
opened 2025-12-29 18:25:38 +01:00 by adam · 3 comments
Owner

Originally created by @hoalex on GitHub (Dec 30, 2019).

Originally assigned to: @jeremystretch on GitHub.

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.9

Proposed Functionality

When editing a device, only show valid values for the "Platform" field, i.e. such platforms that either have a) no manufacturer or b) the manufacturer of the device assigned.

Use Case

Currently, the user is presented with a list of all platforms defined in Netbox. When selecting a platform that has a manufacturer different to that of the device, the following message appears after clicking on "Update":
netbox_platform

Limiting the drop down menu to valid values only makes it easier to find the correct entry when dealing with a large number of platforms and avoids the above error message in the first place.

Database Changes

none

External Dependencies

none

Originally created by @hoalex on GitHub (Dec 30, 2019). Originally assigned to: @jeremystretch on GitHub. ### Environment * Python version: 3.6.8 * NetBox version: 2.6.9 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality When editing a device, only show valid values for the "Platform" field, i.e. such platforms that either have a) no manufacturer or b) the manufacturer of the device assigned. <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Currently, the user is presented with a list of all platforms defined in Netbox. When selecting a platform that has a manufacturer different to that of the device, the following message appears after clicking on "Update": ![netbox_platform](https://user-images.githubusercontent.com/6103894/71584978-4038e700-2b15-11ea-9470-6eee2d278929.png) Limiting the drop down menu to valid values only makes it easier to find the correct entry when dealing with a large number of platforms and avoids the above error message in the first place. ### Database Changes none ### External Dependencies none
adam added the type: bugstatus: accepted labels 2025-12-29 18:25:38 +01:00
adam closed this issue 2025-12-29 18:25:38 +01:00
Author
Owner

@hSaria commented on GitHub (Dec 30, 2019):

I can do the "manufacturer of the device" bit (below), but I'm not sure how additionally list the platforms with no manufacturers.

--- a/netbox/dcim/forms.py
+++ b/netbox/dcim/forms.py
@@ -1339,7 +1339,8 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm):
         widget=APISelect(
             api_url="/api/dcim/manufacturers/",
             filter_for={
-                'device_type': 'manufacturer_id'
+                'device_type': 'manufacturer_id',
+                'platform': 'manufacturer_id'
             }
         )
     )

A platform with no manufacturer is currently assignable to a device with a specific platform, so the above will stop that as it will filter out any platforms with no manufacturers, unless the user picks the device's platform (no manufacturer) first, then the device's manufacturer (a bit janky).

@hSaria commented on GitHub (Dec 30, 2019): I can do the "manufacturer of the device" bit (below), but I'm not sure how additionally list the platforms with no manufacturers. ```diff --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -1339,7 +1339,8 @@ class DeviceForm(BootstrapMixin, TenancyForm, CustomFieldForm): widget=APISelect( api_url="/api/dcim/manufacturers/", filter_for={ - 'device_type': 'manufacturer_id' + 'device_type': 'manufacturer_id', + 'platform': 'manufacturer_id' } ) ) ``` A platform with no manufacturer is currently assignable to a device with a specific platform, so the above will stop that as it will filter out any platforms with no manufacturers, unless the user picks the device's platform (no manufacturer) first, then the device's manufacturer (a bit janky).
Author
Owner

@jeremystretch commented on GitHub (Dec 31, 2019):

Looks like we've worked ourselves into a corner here. The current implementation only allows for filter a) a specific value, or b) null, if the filtering field is nullable. However, manufacturer is required and thus not nullable. (But even if it was, we still want to match on $value OR null.)

The least disruptive solution might be to allow appending +null to the filter_for value and treating it as a special condition. For example:

filter_for={
    'device_type': 'manufacturer_id',
    'platform': 'manufacturer_id+null'
}

Modifying the applicable Javascript would result in the API call GET /api/dcim/platforms/?manufacturer_id=123&manufacturer_id=null (where 123 is the value of the manufacturer field).

I'll take a shot at this and see if it works.

@jeremystretch commented on GitHub (Dec 31, 2019): Looks like we've worked ourselves into a corner here. The current implementation only allows for filter a) a specific value, or b) `null`, if the filtering field is nullable. However, `manufacturer` is required and thus not nullable. (But even if it was, we still want to match on `$value` OR `null`.) The least disruptive solution might be to allow appending `+null` to the `filter_for` value and treating it as a special condition. For example: ```python filter_for={ 'device_type': 'manufacturer_id', 'platform': 'manufacturer_id+null' } ``` Modifying the applicable Javascript would result in the API call `GET /api/dcim/platforms/?manufacturer_id=123&manufacturer_id=null` (where 123 is the value of the manufacturer field). I'll take a shot at this and see if it works.
Author
Owner

@jeremystretch commented on GitHub (Dec 31, 2019):

Looking into this further, we should be able to use additional_query_params. Just need to modify the Javscript to allow for redundant query values.

@jeremystretch commented on GitHub (Dec 31, 2019): Looking into this further, we should be able to use `additional_query_params`. Just need to modify the Javscript to allow for redundant query values.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3101