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

Is it possible to rebuild a single tree?

I can only find documentation for Model.objects.rebuild() which rebuilds all trees. What if I wanted to rebuild a single tree? Is that possible? If it's not possible - does that mean using move_node or insert_node results in rebuilding for all…
Chris
  • 500
  • 6
  • 25
0
votes
1 answer

Fully mapping out object of unknown "depth" (and the most efficient way of finding the "depth" of an object)

I have a "parent" object that has an unknown "depth" of children. My ultimate goal is to be able to fully map this "parent" object of unknown depth with all its levels of children - how would I do this? Each child already has its "depth" associated…
Chris
  • 500
  • 6
  • 25
0
votes
1 answer

TreeNodeChoiceField not iterable in a form - Django

I was wondering if someone was familiar with TreeNodeChoiceField from mptt in Django. I am trying to use this feature in a form to post an article on a blog. But when I try to create a new post it says that the object associated is not iterable.…
0
votes
1 answer

python - mptt for nested lists

I have read a little about mptt solution and I'm trying to implement some sort of translating a nested list into a mptt list. I know, that in this format it's useless, but nested lists can be easily changed with a classes childs or anything…
Gandi
  • 3,522
  • 2
  • 21
  • 31
0
votes
1 answer

How to limit the max deep of recursetree in Django mttp?

I'm using django-mttp. How can I limit the max depth of recursetree? Max=3 Model: class Comment(MPTTModel): """评论表""" nid = models.AutoField(primary_key=True) news = models.ForeignKey( verbose_name="评论文章", to="News", …
William
  • 3,724
  • 9
  • 43
  • 76
0
votes
1 answer

Django mptt, can I delete the default 'name' filed?

I'm following the django-mptt tutorial,and there is a 'name' filed: class Genre(MPTTModel): name = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True,…
William
  • 3,724
  • 9
  • 43
  • 76
0
votes
1 answer

Return a reference of an object instance

I'm working on a MPTT object that will support several database methods. First of is MySQL and MySQLi. Now I've created it like this Mptt - The main object that will load the correct sub object class Mptt { /** * Array of available driver types *…
Ole Aass
  • 173
  • 1
  • 4
0
votes
1 answer

django-mptt and ForeignKey with blank=True

I am using django-mptt in my project models.py: class Category(models.Model): name = models.TextField() parent = models.ForeignKey("self", blank=True, null=True, related_name="sub_category") image =…
Eugene Nagorny
  • 1,626
  • 3
  • 18
  • 32
0
votes
1 answer

Failed lookup for key [category] in [{'True': True, 'False': False, 'None': None}, {}, {},

I'm getting this error Failed lookup for key [category] in [{'True': True, 'False': False, 'None': None}, {}, {}, ....] in my application I have category and subcategory which repeated too much in my view for every function and for child or…
0
votes
1 answer

MySQL, PHP, MPTT: Sort children on weight/cost/menu_order

SELECT node . * , node.page_id, (COUNT( parent.page_id ) - ( sub_tree.depth +1 )) AS depth FROM pages AS node, pages AS parent, pages AS sub_parent, ( SELECT node.page_id, ( COUNT( parent.page_id ) -1 ) AS depth FROM pages AS node,…
0
votes
1 answer

How to set post_id to resolve error : 'django.db.utils.IntegrityError: NOT NULL constraint failed: posts_comment.post_id'?

I am using Django and attempting to add commenting functionality with AJAX. When I click on the submit button for the comment, the action is not being performed and I am instead seeing a 'django.db.utils.IntegrityError: NOT NULL constraint failed:…
Ahmed Yasin
  • 886
  • 1
  • 7
  • 31
0
votes
1 answer

I cannot create category and sub-categories list in home page,django

I can create a category page with sub-categories in a new template but i cannot list all my sub-categories in home page. All i need is a logic to work in home page. Here is my models.py class Category(MPTTModel): name =…
0
votes
1 answer

Outputting all value descendants from a table when ManyToMany Django ORM

There are two tables catalog_product: id |name 10 prod3 9 prod2 8 prod1 11 prod5 catalog_productcategory: (mptt model) id | name | lft | rght | tree_id | level | parent_id 2 root1 1 6 1 0 null 3…
0
votes
1 answer

How to include dropdown menu with django-mptt in template

I want to be able to create dropdown menu using admin panel. At this moment in model I can choose if subpage is children of another and in what order it should be displayed. But I don't know how to implement all of this together in template. Can…
0
votes
1 answer

What is the most efficient way to query a MPTT style table by path?

I have a MySQL table that stores hierarchical data using the MPTT method. The table also has a column in which I store a short string identifier (slug) for each row. I'd like to be able to query the table to find the correct row when given a path…
Mark Perkins
  • 260
  • 2
  • 10