[PR #20718] [MERGED] Closes #19523: Add counter‑cached counts & filters for DeviceType, ModuleType, and RackType #16026

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20718
Author: @pheus
Created: 10/30/2025
Status: Merged
Merged: 11/17/2025
Merged by: @jeremystretch

Base: featureHead: 19523-add-instance-filter-for-devicetype-and-moduletype-countcachefield


📝 Commits (1)

  • d14e741 feat(dcim): Add device, module and rack count filters

📊 Changes

17 files changed (+202 additions, -57 deletions)

View changed files

📝 netbox/dcim/api/serializers_/devicetypes.py (+5 -6)
📝 netbox/dcim/api/serializers_/racks.py (+4 -5)
📝 netbox/dcim/apps.py (+2 -2)
📝 netbox/dcim/filtersets.py (+10 -1)
📝 netbox/dcim/forms/filtersets.py (+22 -3)
📝 netbox/dcim/graphql/filters.py (+11 -1)
📝 netbox/dcim/graphql/types.py (+3 -0)
netbox/dcim/migrations/0218_devicetype_device_count.py (+66 -0)
📝 netbox/dcim/models/devices.py (+4 -0)
📝 netbox/dcim/models/modules.py (+7 -1)
📝 netbox/dcim/models/racks.py (+12 -5)
📝 netbox/dcim/tables/devicetypes.py (+4 -4)
📝 netbox/dcim/tables/modules.py (+4 -4)
📝 netbox/dcim/tables/racks.py (+4 -4)
📝 netbox/dcim/tests/test_api.py (+2 -2)
📝 netbox/dcim/views.py (+5 -15)
📝 netbox/utilities/tests/test_counters.py (+37 -4)

📄 Description

Fixes: #19523

Summary
Extend usage-count filtering via counter caches to cover DeviceType, ModuleType, and RackType.

Implementation

  • Add counter‑cached integer fields:
    • device_count on DeviceType
    • module_count on ModuleType
    • rack_count on RackType
  • Expose numeric lookups in REST and GraphQL (e.g., device_count__gte=10, module_count=0, {rack_count: {gt: 2}).
  • Include migration to add fields and backfill counts.
  • Add a test.

Database Changes
Adds integer fields on the three models listed above.


🔄 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/20718 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/30/2025 **Status:** ✅ Merged **Merged:** 11/17/2025 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `19523-add-instance-filter-for-devicetype-and-moduletype-countcachefield` --- ### 📝 Commits (1) - [`d14e741`](https://github.com/netbox-community/netbox/commit/d14e74179f3f08d2163608d6e30a317a196665e4) feat(dcim): Add device, module and rack count filters ### 📊 Changes **17 files changed** (+202 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/serializers_/devicetypes.py` (+5 -6) 📝 `netbox/dcim/api/serializers_/racks.py` (+4 -5) 📝 `netbox/dcim/apps.py` (+2 -2) 📝 `netbox/dcim/filtersets.py` (+10 -1) 📝 `netbox/dcim/forms/filtersets.py` (+22 -3) 📝 `netbox/dcim/graphql/filters.py` (+11 -1) 📝 `netbox/dcim/graphql/types.py` (+3 -0) ➕ `netbox/dcim/migrations/0218_devicetype_device_count.py` (+66 -0) 📝 `netbox/dcim/models/devices.py` (+4 -0) 📝 `netbox/dcim/models/modules.py` (+7 -1) 📝 `netbox/dcim/models/racks.py` (+12 -5) 📝 `netbox/dcim/tables/devicetypes.py` (+4 -4) 📝 `netbox/dcim/tables/modules.py` (+4 -4) 📝 `netbox/dcim/tables/racks.py` (+4 -4) 📝 `netbox/dcim/tests/test_api.py` (+2 -2) 📝 `netbox/dcim/views.py` (+5 -15) 📝 `netbox/utilities/tests/test_counters.py` (+37 -4) </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** Extend usage-count filtering via counter caches to cover **DeviceType**, **ModuleType**, and **RackType**. **Implementation** - Add counter‑cached integer fields: - `device_count` on **DeviceType** - `module_count` on **ModuleType** - `rack_count` on **RackType** - Expose numeric lookups in **REST** and **GraphQL** (e.g., `device_count__gte=10`, `module_count=0`, `{rack_count: {gt: 2}`). - Include migration to add fields and backfill counts. - Add a test. **Database Changes** Adds integer fields on the three models listed above. --- <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:25:23 +01:00
adam closed this issue 2025-12-30 00:25:24 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16026