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
5
votes
1 answer

Django - what is fk_name?

I'm looking for some help on how to get my Django project admin to work with both, treeadmin drag and drop thingy and with mptt model. Everything worked ok out of box, but when I tried this in my admin.py: class ItemInline(TreeAdmin): model =…
QlliOlli
  • 637
  • 3
  • 13
  • 25
4
votes
2 answers

How to convert this MPTT array into a tree structure in PHP?

I've got hierarchal data in the database, stored in Modified Preorder Tree Traversal format. I'm pulling the data in a query that looks something like "SELECT ID, Left, Right, Name, etc FROM Table ORDER BY Left;". I'm trying to convert this data…
mrdrbob
  • 704
  • 1
  • 7
  • 14
4
votes
6 answers

Finding breadcrumbs for nested sets

I'm using nested sets (aka modified preorder tree traversal) to store a list of groups, and I'm trying to find a quick way to generate breadcrumbs (as a string, not a table) for ALL of the groups at once. My data is also stored using the adjacency…
gregmac
  • 24,276
  • 10
  • 87
  • 118
4
votes
2 answers

How to build django-mptt tree without rebuilding after each insert?

I'm building large mptt tree. I'd like to insert all nodes and after that start method for rebuilding whole tree: for i in range(big_loop): ... m.save() # Saving mptt object. Tree is rebuild. some_mptt_model.tree.rebuild() How can I avoid…
Spodym
  • 173
  • 1
  • 9
4
votes
2 answers

django select_related() and django-mptt. How to fetch all the siblings at once?

I'm trying to fetch all the siblings of the current page. The Page model looks like this: class Page(MPTTModel): title = models.CharField(max_length=255) slug = models.SlugField(max_length=255, blank=True) # changing to CharField from…
Cody
  • 2,480
  • 5
  • 31
  • 62
4
votes
2 answers

Django Making 1000 Duplicate Queries

Model: class Comment(MPTTModel): submitter = models.ForeignKey(User, blank=True, null=True) post = models.ForeignKey(Post, related_name="post_comments") parent = TreeForeignKey('self', blank=True, null=True, related_name="children") …
user1025948
4
votes
2 answers

django-mptt raises django.db.utils.IntegrityError: null value in column "lft" violates not-null constraint

Conditions: Django==1.8.7 и django-mptt==0.8.0. There is a model: class Tree(mptt_models.MPTTModel): name = models.CharField(max_length=120, unique=True) slug = models.SlugField(max_length=256, unique=True) parent =…
Ruslan Popov
  • 333
  • 2
  • 10
4
votes
2 answers

Django mptt database migration error

im trying to get mptt working with my current project, but having issues with the database migration. here is my model from django.db import models from mptt.models import MPTTModel, TreeForeignKey class Section(MPTTModel): name =…
Philippe Fisher
  • 586
  • 7
  • 28
4
votes
2 answers

Deeply nested subqueries for traversing trees in MySQL

I have a table in my database where I store a tree structure using the hybrid Nested Set (MPTT) model (the one which has lft and rght values) and the Adjacency List model (storing parent_id on each node). my_table (id, parent_id, lft, rght,…
nickf
  • 537,072
  • 198
  • 649
  • 721
4
votes
1 answer

Is MPTT an overkill for maintaining a tree like database even if the depth is around 3 - 4?

I am planning to store some tree like data in MySQL. Topics can have sub topics and they in turn can have more sub topics. Is Modified Preorder Tree Traversal(MPTT) an over kill even if the maximum depth is around 3 - 4?
4
votes
3 answers

How to populating Modified Preorder Tree Traversal data into Java tree object?

I have the following table with a MPTT structure : CREATE TABLE IF NOT EXISTS menus ( id int(10) unsigned NOT NULL AUTO_INCREMENT, parent_id int(10) DEFAULT NULL, lft int(10) DEFAULT NULL, rght int(10) DEFAULT NULL, module_name…
4
votes
2 answers

django-mptt filter without breaking the tree

I'm using django-mptt for a Article model in my Django application. If I want to get all Articles which are set to for example hidden, I could do Article.objects.filter(hidden=False) but that would break the mptt-tree. How can I filter on my…
user1614463
3
votes
0 answers

django MPTT model and applying Fixture

I'm using django MPTT model. I subclass MPTT model, but then try to add fixture to the custom model with supplied initial_data in JSON. The parent TreeForeignKey is optional (blank=True, null=True) When I apply a JSON fixture from initial_data, it…
user3044258
  • 99
  • 1
  • 9
3
votes
2 answers

Have multiple trees in one table using CakePHP Tree Behavior

I'm converting a flat list into a tree in my CakePHP app and found that there is an existing behavior that has this functionality. My table is not one giant tree, but consists of many user-generated trees: basically, each user can create their own…
828
  • 1,140
  • 1
  • 12
  • 21
3
votes
1 answer

How to properly sort MPTT hierarchy data into a multidimensional array.

I'm trying to figure out how to write a function that returns a multidimensional array. I know how to write the function using the "category_parent" value. But I'm just trying to write a function that can create a multidimensional array by ONLY…
DiegoMax
  • 91
  • 3
1
2
3
9 10