Object types are not filtered appropriately when filtering custom fields #7658

Closed
opened 2025-12-29 20:26:32 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Feb 19, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.4

Python version

3.8

Steps to Reproduce

  1. View the custom fields list in the UI
  2. Select the "filters" tab
  3. Open the "object type" filter dropdown

Expected Behavior

Only relevant object types (those to which custom fields can be assigned) should be included in the list.

Observed Behavior

All known object types are listed. (This affects several other models too, in addition to custom fields.)

It appears that Django does not acknowledge limit_choices_to when set on fields on non-model forms. Apparently this has never actually been a documented kwarg for ModelChoiceField; its acceptance as a keyword argument seems to be incidental to support for the attribute on ForeignKey models fields.

We'll need to devise an alternative solution for filtering ModelChoiceFields on non-model forms (e.g. CustomFieldFilterForm).

Originally created by @jeremystretch on GitHub (Feb 19, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.4 ### Python version 3.8 ### Steps to Reproduce 1. View the custom fields list in the UI 2. Select the "filters" tab 3. Open the "object type" filter dropdown ### Expected Behavior Only relevant object types (those to which custom fields can be assigned) should be included in the list. ### Observed Behavior All known object types are listed. (This affects several other models too, in addition to custom fields.) It appears that Django does not acknowledge `limit_choices_to` when set on fields on non-model forms. Apparently this has never actually been a documented kwarg for `ModelChoiceField`; its acceptance as a keyword argument seems to be incidental to support for [the attribute on `ForeignKey` models fields](https://docs.djangoproject.com/en/4.1/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to). We'll need to devise an alternative solution for filtering `ModelChoiceFields` on non-model forms (e.g. `CustomFieldFilterForm`).
adam added the type: bugstatus: accepted labels 2025-12-29 20:26:32 +01:00
adam closed this issue 2025-12-29 20:26:33 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7658