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

Django: using mptt-django to allocate products to categories in a many-to-many relationship

I have a many-to-many relationship between products and categories. I am using mptt to manage the display of categories on the admin (which works fine) and so I can allocate products to categories. While the categories are working fine, it's the…
Newfoundland
  • 497
  • 6
  • 17
5
votes
1 answer

How to create nested comment system with django-mptt

I'm working on simple blog and I'm trying to implement a nested comment system for each post. I created model for comments and it's works fine via Django Admin Page. I don't know how to create form for posting new comment and replying. Here is what…
Konrados
  • 508
  • 1
  • 5
  • 13
5
votes
2 answers

django-mptt: how to successfully move nodes around

django-mptt seems determined to drive me out of my mind. I'm trying to do something relatively simple: I'm going to delete a node, and need to do something reasonable with the node's children. Namely, I'd like to move them up one level so they're…
Parand
  • 102,950
  • 48
  • 151
  • 186
5
votes
3 answers

Use field value in limit_choices_to in Django

I have two models Project and Group. My groups belong to a specific project. My groups have the fields project = ForeignKey(Project) and parent = ForeignKey('self'). Can I use limit_choices_to to make sure the options in foreign key parent only…
Jamgreen
  • 10,329
  • 29
  • 113
  • 224
5
votes
1 answer

django-mptt - How to set different models in the same tree

I would like to have a tree that would mimic a file system with folders and files. Folders and files would be defined by different models with different fields attributes. models: from mptt.models import MPTTModel, TreeForeignKey class…
Below the Radar
  • 7,321
  • 11
  • 63
  • 142
5
votes
2 answers

How optimize adding new nodes in `django-mptt`?

I am creating a script which will synchronize two databases. There is a data in the database which should be stored as a tree so I use django-mptt for the new DB. When I syncing DB's I select new data from the old DB and should save it in the new…
idea.list
  • 145
  • 3
  • 5
5
votes
1 answer

order_insertion_by descending ordering?

I'm trying to use the mptt library for a simple nested comment system. My Model class Comment(MPTTModel): event = models.ForeignKey(Event) author = models.CharField(max_length=60) comment = models.TextField() added =…
heifetz
  • 353
  • 1
  • 3
  • 6
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
4 answers

Django- Duplicated queries in nested models querying with ManyToManyField

How do I get rid of the duplicated queries as in the screenshot? I have two models as following, class Genre(MPTTModel): name = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', on_delete=models.CASCADE,…
user5170375
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
3 answers

show children nodes depending on selected parent

Hi i've been looking all over and can't find the answer to this. I have only 3 months experience in using python/django so excuse my dummy quesion! Im using django mptt to display a simple nested set navigation.
    {% recursetree…
zzart
  • 11,207
  • 5
  • 52
  • 47
4
votes
1 answer

How to add django-mptt rebuild to migration?

I have add the django-mptt to existing database, and create the new migration. Migration process was asked for default values for level, left, right and such fields, but doesn't add the model.rebuild operation to migration file. How to add rebuild…
Y.N
  • 4,989
  • 7
  • 34
  • 61
4
votes
0 answers

Django MPTT filter on related model

Let's say I have a model Album: class Genre(MPTTModel): name = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True) And a model called Album like this class…
XelharK
  • 598
  • 8
  • 21
4
votes
2 answers

In django, how to serialize mptt tree?

The follows is my code: class File(MPTTModel): name=models.CharField(max_length=36, primary_key=True) parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True) num=models.IntegerField(null=True) …
pfc
  • 1,831
  • 4
  • 27
  • 50
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
1 2
3
23 24