Questions tagged [mptt]

mptt refers to "Modified Preorder Tree Traversal" algorithm for storing hierarchical data

mptt refers to "Modified Preorder Tree Traversal" algorithm for storing hierarchical data.

See also:

146 questions
28
votes
1 answer

Django treebeard what are differences between AL, NS, MP

I'm trying to make a model for categorizing some objects. I already tried using django-mptt to easily retrieve related categories, and now I'm searching different solutions to find the best one. I can't find out though what are main differences…
aherok
  • 622
  • 7
  • 17
24
votes
4 answers

How to repair a corrupted MPTT tree (nested set) in the database using SQL?

I have an MPTT tree of over 100,000 records stored in MySQL using lft, rght and parent_id columns. Now the left/right values became corrupted, while the parent ids are still intact. It would require tons of queries to repair it in the application…
deceze
  • 510,633
  • 85
  • 743
  • 889
23
votes
6 answers

Building hierarchy objects from flat list of parent/child

I have a list of items in a hierarchy, and I'm attempting to parse this list out into an actual hierarchy of objects. I'm using modified pre-order tree traversal to store/iterate through this list, and so what I have is a subset of the tree,…
gregmac
  • 24,276
  • 10
  • 87
  • 118
17
votes
2 answers

efficient function to retrieve a queryset of ancestors of an mptt queryset

Does anybody have an efficient algorithm to retrieve all ancestors of an mptt queryset? The best I could think of so far is something like this: def qs_ancestors(queryset): if isinstance(queryset, EmptyQuerySet): return queryset …
Bacon
  • 2,155
  • 4
  • 23
  • 31
15
votes
3 answers

django-mptt get_descendants for a list of nodes

I am trying to get all descendants(include_self=True) not for one Node, but for a list (a QuerySet) of Nodes. This should be one SQL query. Example (that actually is not working:) some_nodes = Node.objects.filter( ...some_condition... )…
thedk
  • 1,939
  • 1
  • 20
  • 22
13
votes
2 answers

Managing hierarchies in SQL: MPTT/nested sets vs adjacency lists vs storing paths

For a while now I've been wrestling with how best to handle hierarchies in SQL. Frustrated by the limitations of adjacency lists and the complexity of MPTT/nested sets, I began thinking about simply storing key paths instead, as a simple…
Yarin
  • 173,523
  • 149
  • 402
  • 512
13
votes
3 answers

How do I query objects of all children of a node with Django mptt?

I am trying to get the objects of all the children of a given node on Django with django-mppt I have a model designed as shown below, the classes/categories (node) with the same indent level defines siblings, inner indents are children. The objects…
user5170375
10
votes
1 answer

Rails ACL Using Modified Preorder Tree Traversal

Is there a Rails ACL plugin/gem that uses MPTT (Modified Preorder Tree Traversal) as the technique to administer permissions? I'm looking for ACL that will allow me to create roles, assign users to one or many roles, set permissions at the role…
Brandon Cordell
  • 1,308
  • 1
  • 9
  • 24
10
votes
1 answer

how to prefetch parents of a child on mptt tree with django prefetch_related?

Say, I've got a product instance. Product instance linked to 4th level child category. If I only want to get root category and 4th level child category the query below is enough to fetch data with minimum database…
Sencer H.
  • 1,201
  • 1
  • 13
  • 35
8
votes
2 answers

Django MPTT Postgres update query runs slowly

I'm using mptt in a model to manage a tagging system (each tag has an optional TreeForeignKey to a 'parent' tag) Whenever I need to save a tag model, the following query runs exceptionally slow (upwards of 45 seconds) UPDATE "taxonomy_taxonomy" SET…
Robert Townley
  • 3,414
  • 3
  • 28
  • 54
8
votes
3 answers

data structure for traversal tree in PHP?

I don't have a background in CS or data structures. I want to make a PHP class that stores a modified preorder transversal tree, for manipulation and syncing with a database. Basically I need to store data…
user151841
  • 17,377
  • 29
  • 109
  • 171
7
votes
1 answer

Django-mptt completely buggy or am I doing it wrong?

I'm attempting to use django-mptt with very little luck. This is with Python2.5, windows, sqlite3, Django 1.2pre , django-mptt latest from svn. The code: model: class Node(models.Model): name = models.CharField(max_length=20, blank=True) …
Parand
  • 102,950
  • 48
  • 151
  • 186
7
votes
1 answer

Finding a subtree in a CakePHP Tree

In CakePHP, how do you select just a subtree in a model which actsAs tree? I tried this, to find the tree headed by the item with label = "My Label" $this->find("threaded", array( "conditions" => array( "label" => "My Label" …
nickf
  • 537,072
  • 198
  • 649
  • 721
6
votes
1 answer

Storing hierarchical (parent/child) data in Python/Django: MPTT alternative?

I'm looking for a good way to store and use hierarchical (parent/child) data in Django. I've been using django-mptt, but it seems entirely incompatible with my brain - I end up with non-obvious bugs in non-obvious places, mostly when moving things…
Parand
  • 102,950
  • 48
  • 151
  • 186
5
votes
2 answers

How to serialize a Django MPTT family and keep it hierarchical?

I was trying to find solution for this (Google cache) And I could only came up with a solution like this: import json from mptt.utils import tree_item_iterator from rest_framework import generics from rest_framework.response import Response from…
diogosimao
  • 163
  • 2
  • 9
1
2 3
9 10