Django MPTT is no longer maintained - Migrate Existing Models to `django-tree-queries`
See original GitHub issueProposed Changes
The django-mptt project is no longer maintained so we need to find a new pattern for our tree use cases (Regions, rack groups, etc). I think we should revisit these use cases related to storage and access patterns to see if we really need the complexity of the MPTT structure, to begin with.
Justification
The django-mptt project is no longer maintained and as a core dependency, we need to find an alternative path.
TODO
Migrate
- RackGroup
- TenantGroup
- InventoryItem
Footnote: Region
is an MPTT model but should be collapsed into Location
sometime in this release and either this issue or that one can be the one to “turn the lights off” on MPTT (See: #2517)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Django mptt database migration error - Stack Overflow
Please select a fix: 1) Provide a one-off default now (will be set on all existing rows) 2) Quit, and let me add...
Read more >Models and Managers — django-mptt 0.14.0 documentation
Models and Managers. Setting up a Django model for MPTT; Model Options; Registration of existing models; MPTTModel instance methods.
Read more >django-mptt - PyPI
Utilities for implementing Modified Preorder Tree Traversal with your Django Models and working with trees of Model instances.
Read more >Django-mptt: Utilities for implementing Modified Preorder Tree ...
In this tutorial, we will share a repository of Django-mptt: Utilities for implementing a modified pre-order traversal tree in django.
Read more >django-mptt Documentation - Read the Docs
from mptt.models import MPTTModel, TreeForeignKey ... Warning: Does not work well with big trees (more than a few hundred nodes, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Requirements
The main requirements, as I understand them are:
get_ancestors()
)nautobot/dcim/templates/dcim/site.html
and others -for region in object.region.get_ancestors
etc.get_children()
,get_descendants()
)nautobot.dcim.signals.handle_rackgroup_site_change
- recursively setting the Site of all child RackGroups when a parent RackGroup changes SiteTreeNodeMultipleChoiceFilter
- “get me all Sites that belong to Region ABC or any of its descendants”ConfigContextModelQuerySet
- “get me all ConfigContexts that are assigned to Region XYZ or any of its ancestors”add_related_count
RegionListView
- “How many Sites belong to each of the following Regions or any of their descendants”RackGroupListView
- “How many Racks belong to each of the following RackGroups or any of their descendants”name
), as opposed to un-ordered treesNon-requirements
name
or other field that is hard-coded for sorting) - see also #1854Comparison of approaches
Based on my limited research and understanding to date.
Another useful feature I’ve identified a potential need/benefit for is the ability to select a subtree and/or set of nodes based on ancestor properties - e.g. “get me all of the Locations who have an ancestor of type Campus”, “get me the subtrees of Locations descended from Location ABC or Location XYZ”, “get me the subtrees of Locations descended from a Location that is linked to Site PDQ”.
queryset.get_ancestors()
andqueryset.get_descendants()