Closes #19523: Add instance count filter to Module and Device Types #1299

Closed
opened 2026-04-05 23:12:07 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 9/7/2025

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.
*Originally created by @pheus on 9/7/2025* <!-- 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.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1299