Replace FeatureQuery with a custom manager method for ContentType #8793

Closed
opened 2025-12-29 20:41:15 +01:00 by adam · 1 comment
Owner

Originally created by @jeremystretch on GitHub (Oct 31, 2023).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

NetBox uses the FeatureQuery class to filter ContentType querysets by support for a specific feature. For example, to retrieve the content types corresponding to all models which support the assignment of jobs:

queryset=ContentType.objects.filter(FeatureQuery('jobs').get_query())

This proposal is to move this logic to a custom manager method for ContentType, such that we could instead do:

queryset=ContentType.objects.with_feature('jobs')

In addressing #13427, PR #14152 proposes introduce a proxy model and custom manager for ContentType, which would be easily extended to support this implementation.

Justification

FeatureQuery has always felt cumbersome to use, and is not invoked consistently for all use cases (i.e. sometimes get_query() is needed and sometimes not). The proposed approach provides a much cleaner mechanism for filtering ContentTypes by supported feature.

Originally created by @jeremystretch on GitHub (Oct 31, 2023). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes NetBox uses the FeatureQuery class to filter ContentType querysets by support for a specific feature. For example, to retrieve the content types corresponding to all models which support the assignment of jobs: ```python queryset=ContentType.objects.filter(FeatureQuery('jobs').get_query()) ``` This proposal is to move this logic to a custom manager method for ContentType, such that we could instead do: ```python queryset=ContentType.objects.with_feature('jobs') ``` In addressing #13427, PR #14152 proposes introduce a proxy model and custom manager for ContentType, which would be easily extended to support this implementation. ### Justification FeatureQuery has always felt cumbersome to use, and is not invoked consistently for all use cases (i.e. sometimes `get_query()` is needed and sometimes not). The proposed approach provides a much cleaner mechanism for filtering ContentTypes by supported feature.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 20:41:15 +01:00
adam closed this issue 2025-12-29 20:41:15 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 1, 2023):

Blocked by #13427

@jeremystretch commented on GitHub (Nov 1, 2023): Blocked by #13427
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8793