Add option to filter 'devices' by 'region' #1968

Closed
opened 2025-12-29 17:21:00 +01:00 by adam · 3 comments
Owner

Originally created by @bdlamprecht on GitHub (Aug 22, 2018).

Environment

  • Python version: 3.6
  • NetBox version: v2.4.3

Proposed Functionality

Currently, the WebUI does not allow to you filter devices by regions, only by sites.
As mentioned by @john in the NetworkToCode Slack:

You can achieve your desired result in two steps. Just query for all sites in your region, then query for devices in any of those sites.
/api/dcim/devices/?site_id=3&site_id=4&site_id=5&...

This in fact DOES work for someone who is familiar with coding and use of the API, however, for someone who does not (read: management), this is less than ideal.

My request is, if it would be possible to implement that filter in the WebUI?
As @john mentioned also:

Regions only have to do with Sites. The only reason you see Region in the Device form is because it is used to filter the list of Sites. The Region value is not attached to the device.

That being said, in the nbshell you can do something like Device.objects.filter(site__region=region)
In that case you are using Site as a through model to get to Region.

The reason you can't filter on Region in the actual app is because our filters are only setup with fields that are on the model.

I'm not a developer by trade (learning as I have the time 😄 ), so if it is impossible with the way NetBox currently works with primary model and the related fields, then so be it. However, that fact that you can do it in the nbshell makes me wonder.

Use Case

Implementing this feature would allow greater flexibility in the WebUI to search for, as an example, all device_types of Cisco 3850-12S in the region Austin, TX.

Database Changes

Most likely, none.

External Dependencies

None.

Originally created by @bdlamprecht on GitHub (Aug 22, 2018). ### Environment * Python version: 3.6 * NetBox version: v2.4.3 ### Proposed Functionality Currently, the WebUI does not allow to you filter `devices` by regions, only by `sites`. As mentioned by `@john` in the NetworkToCode Slack: >You can achieve your desired result in two steps. Just query for all sites in your region, then query for devices in any of those sites. `/api/dcim/devices/?site_id=3&site_id=4&site_id=5&...` This in fact **DOES** work for someone who is familiar with coding and use of the API, however, for someone who does not (read: management), this is less than ideal. My request is, if it would be _**possible**_ to implement that filter in the WebUI? As `@john` mentioned also: > Regions only have to do with Sites. The only reason you see Region in the Device form is because it is used to filter the list of Sites. The Region value is not attached to the device. >That being said, in the nbshell you can do something like `Device.objects.filter(site__region=region)` In that case you are using Site as a through model to get to Region. >The reason you can't filter on Region in the actual app is because our filters are only setup with fields that are on the model. I'm not a developer by trade (learning as I have the time :smile: ), so if it is impossible with the way NetBox currently works with primary `model` and the related `fields`, then so be it. However, that fact that you can do it in the `nbshell` makes me wonder. ### Use Case Implementing this feature would allow greater flexibility in the WebUI to search for, as an example, all `device_types` of `Cisco 3850-12S` in the `region` Austin, TX. ### Database Changes Most likely, none. ### External Dependencies None.
adam added the status: acceptedtype: feature labels 2025-12-29 17:21:00 +01:00
adam closed this issue 2025-12-29 17:21:00 +01:00
Author
Owner

@bdlamprecht commented on GitHub (Oct 4, 2018):

Has there been any discussion on this FR yet?
I continue to run into the need for this functionality but don't know if it is going to be implemented at all.

I suppose my question is this...
Do I and need to find another solution for it or does this have the potential for being implemented?

@bdlamprecht commented on GitHub (Oct 4, 2018): Has there been any discussion on this FR yet? I continue to run into the need for this functionality but don't know if it is going to be implemented at all. I suppose my question is this... Do I and need to find another solution for it or does this have the _potential_ for being implemented?
Author
Owner

@jeremystretch commented on GitHub (Nov 6, 2018):

FYI the trick with this was matching on parent regions as well. For example, ?region=europe should match all devices assigned to a region within Europe as well as Europe itself.

@jeremystretch commented on GitHub (Nov 6, 2018): FYI the trick with this was matching on parent regions as well. For example, `?region=europe` should match all devices assigned to a region _within_ Europe as well as Europe itself.
Author
Owner

@bdlamprecht commented on GitHub (Nov 6, 2018):

Awesome, thank you so much!

@bdlamprecht commented on GitHub (Nov 6, 2018): Awesome, thank you so much!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1968