Questions tagged [django-mptt]

django-mptt is an implementation Modified Preorder Tree Traversal for handling trees of Django Model instances.

django-mptt is an implementation Modified Preorder Tree Traversal for handling trees of Django Model instances.

Useful links:

351 questions
44
votes
6 answers

Django - How to get self.id when saving a new object?

I have a problem in one of my models. I'm uploading an image, and I want to store the id (pk in the database table) but I need to know at which point Django will have access to self.id. models.py class BicycleAdItemKind(MPTTModel): def…
André
  • 24,706
  • 43
  • 121
  • 178
24
votes
1 answer

Django - proper way to implement threaded comments

I'm developing a blog site using Django. My site will allow users to comment on any of my blog posts and also reply to each other and will be displayed using a 'threaded comments' structure (I haven't started user functionality yet, just comments).…
Bryan Hinchliffe
  • 529
  • 1
  • 4
  • 14
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
17
votes
4 answers

How do I rebuild my django-mptt tree?

I'm using django-mptt 0.4.2, and want to rebuild a tree. The tree manager has a method rebuild() which I try to access like this: >>> my_rootnode = MyObj.objects.get(id=12) >>> my_rootnode.tree.rebuild() Traceback (most recent call last): File…
Hobhouse
  • 15,463
  • 12
  • 35
  • 43
16
votes
5 answers

Django and MPTT - get only leaf nodes

I'm new to Django and MPTT and having hard time figuring out how to get all leaf nodes and send them directly to Form class. For example, I have created MPTT Category Model, and have hierarchy like…
Zed
  • 5,683
  • 11
  • 49
  • 81
15
votes
1 answer

Why this database migration error after I upgrade my version django-mptt?

My Django application has a requirements.txt file (shown here) that I use to install modules in my virtual environment. Everything works fine. However, I'm now trying to upgrade django-mptt from 0.6.1 to the latest version. (I actually don't care to…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
14
votes
3 answers

What are the advantages of django-treebeard over django-mptt?

There are two well known Django packages for creating tree structures: django-treebeard and django-mptt. Recently Django CMS started using django-treebeard instead of django-mptt. Wagtail CMS is also using django-treebeard. What makes…
Aidas Bendoraitis
  • 3,965
  • 1
  • 30
  • 45
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
12
votes
1 answer

Django-mptt and multiple parents?

I've been banging my head against the desk for a couple weeks on this problem, so I figure it may be time to seek some help. I'm trying to implement a database structure which has hierarchical data of parts for assemblies. My main problem lies with…
j_syk
  • 6,511
  • 2
  • 39
  • 56
12
votes
6 answers

How can create a json tree from django-mptt?

I want to use the JavaScript InfoVis Tooljit ( http://thejit.org ) to render a tree of mptt nodes in django. How can i create the required json structure (see http://thejit.org/static/v20/Jit/Examples/Spacetree/example1.code.html for an example) in…
sean2000
  • 506
  • 4
  • 12
9
votes
1 answer

Dynamic order in django-mptt

I am using a django-mptt package for my comments application and I have following model for this: class Comment(MPTTModel): content = models.TextField(verbose_name='Treść') author = models.ForeignKey(AUTH_USER_MODEL, verbose_name='Autor',…
Peterek
  • 93
  • 4
9
votes
1 answer

Hierarchical data in admin pages in Django

In a Django project, I have a hierarchical model using MPTT defined like this in models.py: class Structure(MPTTModel): name = models.CharField(max_length=200, unique=True) parent = TreeForeignKey('self', null=True, blank=True,…
A.Vila
  • 1,456
  • 4
  • 21
  • 32
9
votes
4 answers

Django-MPTT full path to child pages how to make?

I'm start using Django-MPTT app to get a tree-based approach on my Django-site pages. For ex. I have pages with sub pages: Trance: Vocal Trance(sub page) Hard Trance(sub page) Breaks: Atmo Breaks(sub page) Progressive Breaks(sub page) How can I…
Swordfish
  • 181
  • 1
  • 5
8
votes
2 answers

Django-mptt order

In my project I am using django-mptt for categories. My model: class Category(models.model): name = models.CharField() parent = models.ForeignKey("self", blank=True, null=True, related_name="sub_category") …
Eugene Nagorny
  • 1,626
  • 3
  • 18
  • 32
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
1
2 3
23 24