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.
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":

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.
none
none
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).
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.
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.
Most helpful comment
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.