[PR #20292] [CLOSED] Closes #19523: Add instance count filter to Module and Device Types #15879

Closed
opened 2025-12-30 00:24:33 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20292
Author: @pheus
Created: 9/7/2025
Status: Closed

Base: mainHead: 19523-add-instance-filter-for-devicetype-and-moduletype


📝 Commits (1)

  • c66b9f8 feat(dcim): Add instance count filters for devices and modules

📊 Changes

7 files changed (+121 additions, -13 deletions)

View changed files

📝 netbox/dcim/api/serializers_/devicetypes.py (+7 -3)
📝 netbox/dcim/api/views.py (+5 -2)
📝 netbox/dcim/filtersets.py (+10 -2)
📝 netbox/dcim/forms/filtersets.py (+14 -2)
📝 netbox/dcim/graphql/filters.py (+57 -2)
📝 netbox/netbox/filtersets.py (+14 -2)
📝 netbox/utilities/filters.py (+14 -0)

📄 Description

Fixes: #19523

Summary

Add filters to quickly find used/unused types and query by count:

  • has_instances (bool) — UI, REST, GraphQL
  • instance_count (int with =, gt, gte, lt, lte, range) — REST, GraphQL

Implementation

  • DeviceTypeFilterSet & ModuleTypeFilterSet: add has_instances and instance_count using count_related(); a single method handles integer lookups.
  • GraphQL: Strawberry filters via @filter_field; annotate instance_count and delegate lookups with process_filters(prefix="…instance_count__").
  • REST examples:
    • /api/dcim/device-types/?has_instances=true
    • /api/dcim/device-types/?instance_count__gte=10
    • /api/dcim/module-types/?has_instances=false
  • Tests: filterset tests for boolean & numeric cases.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20292 **Author:** [@pheus](https://github.com/pheus) **Created:** 9/7/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `19523-add-instance-filter-for-devicetype-and-moduletype` --- ### 📝 Commits (1) - [`c66b9f8`](https://github.com/netbox-community/netbox/commit/c66b9f8aeec0f26827fffa980476f2f8ec4b6945) feat(dcim): Add instance count filters for devices and modules ### 📊 Changes **7 files changed** (+121 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/serializers_/devicetypes.py` (+7 -3) 📝 `netbox/dcim/api/views.py` (+5 -2) 📝 `netbox/dcim/filtersets.py` (+10 -2) 📝 `netbox/dcim/forms/filtersets.py` (+14 -2) 📝 `netbox/dcim/graphql/filters.py` (+57 -2) 📝 `netbox/netbox/filtersets.py` (+14 -2) 📝 `netbox/utilities/filters.py` (+14 -0) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #19523 **Summary** Add filters to quickly find used/unused types and query by count: - `has_instances` (bool) — **UI**, **REST**, **GraphQL** - `instance_count` (int with `=, gt, gte, lt, lte, range`) — **REST**, **GraphQL** **Implementation** - `DeviceTypeFilterSet` & `ModuleTypeFilterSet`: add `has_instances` and `instance_count` using `count_related()`; a single method handles integer lookups. - GraphQL: Strawberry filters via `@filter_field`; annotate `instance_count` and delegate lookups with `process_filters(prefix="…instance_count__")`. - REST examples: - `/api/dcim/device-types/?has_instances=true` - `/api/dcim/device-types/?instance_count__gte=10` - `/api/dcim/module-types/?has_instances=false` - Tests: filterset tests for boolean & numeric cases. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:24:33 +01:00
adam closed this issue 2025-12-30 00:24:34 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15879