Add abstract tree model to plugins API #11494

Closed
opened 2025-12-29 21:46:00 +01:00 by adam · 3 comments
Owner

Originally created by @alehaa on GitHub (Aug 17, 2025).

NetBox version

v4.3.6

Feature type

Other

Proposed functionality

I suggest adding a new abstract model to the plugins API for implementing tree structures. For implementation, I propose copying NestedGroupModel to NetBoxTreeModel including the parent field only. All other fields remain in NestedGroupModel, now being a child of NetBoxTreeModel.

I’m aware of #12552, but I believe we can still agree on a new implementation will includes a parent field and implement some kind of tree structure. Additionally, plugins should follow the same approach as NetBox during transitioning. However, it would be beneficial to include a note in the documentation that links to #12552.

Use case

Nesting models is a fundamental feature of NetBox, so plugins shouldn’t reinvent the wheel when implementing similar structures. Examples of use cases include or are:

Database changes

None

External dependencies

None

Originally created by @alehaa on GitHub (Aug 17, 2025). ### NetBox version v4.3.6 ### Feature type Other ### Proposed functionality I suggest adding a new abstract model to the plugins API for implementing tree structures. For implementation, I propose copying `NestedGroupModel` to `NetBoxTreeModel` including the `parent` field only. All other fields remain in `NestedGroupModel`, now being a child of `NetBoxTreeModel`. I’m aware of #12552, but I believe we can still agree on a new implementation will includes a `parent` field and implement some kind of tree structure. Additionally, plugins should follow the same approach as NetBox during transitioning. However, it would be beneficial to include a note in the documentation that links to #12552. ### Use case Nesting models is a fundamental feature of NetBox, so plugins shouldn’t reinvent the wheel when implementing similar structures. Examples of use cases include or are: * https://github.com/ArnesSI/netbox-inventory/blob/6fd0652/netbox_inventory/models/assets.py#L20 * https://github.com/Alef-Burzmali/netbox-data-flows/blob/bc8af7d/netbox_data_flows/models/groups.py#L30 * https://github.com/netbox-community/netbox-acls/issues/268 ### Database changes None ### External dependencies None
adam added the type: feature label 2025-12-29 21:46:00 +01:00
adam closed this issue 2025-12-29 21:46:00 +01:00
Author
Owner

@arthanson commented on GitHub (Aug 18, 2025):

@alehaa I'm not sure I follow what this is getting the plugin author, are you just asking to define:

class NestedTreeModel(MPTTModel):
    parent = TreeForeignKey(
        to='self',
        on_delete=models.CASCADE,
        related_name='children',
        blank=True,
        null=True,
        db_index=True
    )

is this just an alternative if you don't want the name, description, comment from using the NestedGroupModel?

@arthanson commented on GitHub (Aug 18, 2025): @alehaa I'm not sure I follow what this is getting the plugin author, are you just asking to define: ``` class NestedTreeModel(MPTTModel): parent = TreeForeignKey( to='self', on_delete=models.CASCADE, related_name='children', blank=True, null=True, db_index=True ) ``` is this just an alternative if you don't want the name, description, comment from using the NestedGroupModel?
Author
Owner

@alehaa commented on GitHub (Aug 18, 2025):

Yeah, that’s pretty much it. Honestly, I don’t care whether it’s NestedTreeModel or NestedGroupModel; unused fields can be masked in Django. However, none of these models are part of the official plugins API, forcing each plugin to add a dependency to MPTT and commit to a specific implementation. Therefore, making it an official standard would clarify it for plugin developers.

@alehaa commented on GitHub (Aug 18, 2025): Yeah, that’s pretty much it. Honestly, I don’t care whether it’s `NestedTreeModel` or `NestedGroupModel`; unused fields can be masked in Django. However, none of these models are part of the official plugins API, forcing each plugin to add a dependency to MPTT and commit to a specific implementation. Therefore, making it an official standard would clarify it for plugin developers.
Author
Owner

@jnovinger commented on GitHub (Aug 21, 2025):

Given #12552's current status, we're not prepared to commit to API stability for nested model handling in core NetBox right now. Supporting nested models properly would require significant ongoing maintenance resources to handle edge cases, migration complexity, and compatibility across different use cases.

@jnovinger commented on GitHub (Aug 21, 2025): Given #12552's current status, we're not prepared to commit to API stability for nested model handling in core NetBox right now. Supporting nested models properly would require significant ongoing maintenance resources to handle edge cases, migration complexity, and compatibility across different use cases.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11494