Transition TreeNodeChoiceFields to API-driven DynamicModelChoiceFields #3847

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

Originally created by @jeremystretch on GitHub (Jul 8, 2020).

Originally assigned to: @jeremystretch on GitHub.

Proposed Changes

NetBox currently uses two form fields provided by django-mptt, TreeNodeChoiceField and TreeNodeMultipleChoiceField, for representing relationships to MPTT-enabled (nested) models. (These models currently include regions, rack groups, and tenant groups.)

This issue proposes replacing these form fields with DynamicModelChoiceField and DynamicModelMultipleChoiceField, respectively, which populate options using the REST API. To accomplish this, we'll need to convey the MPTT depth of each item via its API representation; e.g. by adding a numeric depth field. This will allow us to accurately represent the nested relationship of each item in the form widget.

Justification

Most other object relationships now use API-driven form fields. For some reason, we never got around to making the transition for MPTT models.

Originally created by @jeremystretch on GitHub (Jul 8, 2020). Originally assigned to: @jeremystretch on GitHub. ### Proposed Changes NetBox currently uses two form fields provided by [django-mptt](https://github.com/django-mptt/django-mptt), TreeNodeChoiceField and TreeNodeMultipleChoiceField, for representing relationships to MPTT-enabled (nested) models. (These models currently include regions, rack groups, and tenant groups.) This issue proposes replacing these form fields with DynamicModelChoiceField and DynamicModelMultipleChoiceField, respectively, which populate options using the REST API. To accomplish this, we'll need to convey the MPTT depth of each item via its API representation; e.g. by adding a numeric `depth` field. This will allow us to accurately represent the nested relationship of each item in the form widget. ### Justification Most other object relationships now use API-driven form fields. For some reason, we never got around to making the transition for MPTT models.
adam added the status: acceptedtype: housekeeping labels 2025-12-29 18:31:35 +01:00
adam closed this issue 2025-12-29 18:31:35 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3847