DynamicModelChoiceField and DynamicModelMultipleChoiceField should accept a model, not queryset #4379

Closed
opened 2025-12-29 18:35:26 +01:00 by adam · 2 comments
Owner

Originally created by @jeremystretch on GitHub (Dec 18, 2020).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

Replace the queryset keyword argument on DynamicModelChoiceField and DynamicModelMultipleChoiceField with model.

Justification

Since these models fetch available choices using NetBox's REST API, the use of queryset is misleading. The provided queryset isn't actually used when retrieving choices, so calling queryset methods like filter() and prefetch_related() have no impact. Specifying only the base model for the field is simpler and draws attention to the use of query_params for filtering choices.

Originally created by @jeremystretch on GitHub (Dec 18, 2020). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes Replace the `queryset` keyword argument on DynamicModelChoiceField and DynamicModelMultipleChoiceField with `model`. ### Justification Since these models fetch available choices using NetBox's REST API, the use of `queryset` is misleading. The provided queryset isn't actually used when retrieving choices, so calling queryset methods like `filter()` and `prefetch_related()` have no impact. Specifying only the base model for the field is simpler and draws attention to the use of `query_params` for filtering choices.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:35:26 +01:00
adam closed this issue 2025-12-29 18:35:26 +01:00
Author
Owner

@stale[bot] commented on GitHub (Feb 2, 2021):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@stale[bot] commented on GitHub (Feb 2, 2021): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@jeremystretch commented on GitHub (Nov 18, 2021):

After making these changes application-wide, the the test suite seems to take ~10-12 seconds longer to run. I'm not sure why this is, but it's probably not worth the effort to chase down. I'm going to abandon this effort as there isn't really anything wrong with just using querysets directly.

@jeremystretch commented on GitHub (Nov 18, 2021): After making these changes application-wide, the the test suite seems to take ~10-12 seconds longer to run. I'm not sure why this is, but it's probably not worth the effort to chase down. I'm going to abandon this effort as there isn't really anything wrong with just using querysets directly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4379