Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace FeatureQuery with a custom manager method for ContentType #14153

Closed
jeremystretch opened this issue Oct 31, 2023 · 1 comment
Closed
Assignees
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Milestone

Comments

@jeremystretch
Copy link
Member

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.

@jeremystretch jeremystretch added type: housekeeping Changes to the application which do not directly impact the end user status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Oct 31, 2023
@jeremystretch jeremystretch self-assigned this Nov 1, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Nov 1, 2023
@jeremystretch jeremystretch added this to the v3.7 milestone Nov 1, 2023
@jeremystretch jeremystretch added status: blocked Another issue or external requirement is preventing implementation and removed status: accepted This issue has been accepted for implementation labels Nov 1, 2023
@jeremystretch
Copy link
Member Author

Blocked by #13427

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: blocked Another issue or external requirement is preventing implementation labels Nov 6, 2023
jeremystretch added a commit that referenced this issue Nov 16, 2023
* WIP

* Remove FeatureQuery

* Standardize use of proxy ContentType for models

* Remove TODO

* Correctly filter BookmarksWidget object_types choices

* Add feature-specific object type validation
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: housekeeping Changes to the application which do not directly impact the end user
Projects
None yet
Development

No branches or pull requests

1 participant