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

django-mptt tree rebuild error

I used django-mptt version (0,5,'+dev') My model looks like: class Comment(MPTTModel): content = models.CharField(max_length = 300) parent = TreeForeignKey('self', null=True, blank=True, related_name='child') class MPTTMeta: …
hushwings
  • 151
  • 2
  • 8
3
votes
0 answers

What is the best way of implementing hierarchical models in django-nonrel with MongoDB engine?

Essentially I want to duplicate the functionality of the django-mptt module but in django-nonrel using the MongoDB engine. Does anything like this exist already? Edit: I know there are various solutions to storing hierarchical data in Mongo…
ACGray
  • 666
  • 3
  • 10
3
votes
1 answer

Django, how to do CRUD with django-mptt?

How we can implement CRUD functionality using generic views and django-mptt ?? I've searched a lot and couldn't find a single tutorial/sample code. Let's say we have a Course hierarchy or Category hierarchy, or similar thing ... How we can…
Soask
  • 691
  • 12
  • 21
3
votes
1 answer

Django-MPTT leaf nodes of multiple types

I am developing a hirerchical application where leaf nodes can be instances of different models. I can't figure out how to make it work with django-mptt app. Is this even possible in that application? If yes, what am I doing wrong? and if no, is…
miki725
  • 27,207
  • 17
  • 105
  • 121
2
votes
1 answer

MPTT - How to override "tree_id"

I want to override the tree_id field as following: Given: class Thing(MPTTModel): thing_id = models.AutoField(primary_key=True) ... class MPTTMeta: tree_id = ? While creating the "Thing" first parent I want to initiate tree_id…
bentzy
  • 301
  • 2
  • 4
  • 15
2
votes
1 answer

Django MPTT get related objects

I have a category tree and i'd like to get all products that are in the category tree. MPTT's documentation indicates that it only has methods that you can call to get objects. I'm wondering how i can get it to work with related objects, for…
leech
  • 8,293
  • 7
  • 62
  • 78
2
votes
3 answers

How would you sort a django mptt tree?

Imagine that I have an mptt tree of objects and their population like: Animal, 60 aardvark, 30 bobcat, 20 chipmunk, 10 Vegetable, 6 apple, 1 beet, 2 cauliflower, 3 Mineral 0 How would you sort the above by population on each sublevel? I want…
G Ben
2
votes
1 answer

I pass Django json data to Jstree, but it doesn't work fine

I use in Django + django-mptt to complete a win-explorer-tree-like interface with jstree: {% load mptt_tags %} var nodedata = { "data": { {% recursetree nodes %} "data": "{{ node.nodename }}", "id": "{{ node.id }}", …
Gagiel
  • 45
  • 5
2
votes
1 answer

Django multiple caches backends

I want to use multiple caching engines in one django project. In example I use sorl.thumbnail, that generated many sql queries to get/set thumbnail for model image. For caching this queries I use memcached backend. But, other caches stopped working,…
Igor
  • 479
  • 5
  • 13
2
votes
1 answer

Set Unique Constraint only under the direct parents (Django MPTT)

I created "Category" model with Django MPTT: from django.db import models from mptt.models import MPTTModel, TreeForeignKey class Category(MPTTModel): name = models.CharField(max_length=50) parent = TreeForeignKey( "self", …
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
2
votes
0 answers

Django admin mptt: how to show TreeNodeChoiceField instead of ModelChoiceField when add/change with FK

I'm working on a Django app that includes some mptt based tree models. I have these models (simplified): class Asset_Type(MPTTModel): parent = TreeForeignKey('self', on_delete=models.CASCADE, blank=True, null=True, related_name='children',…
Otura
  • 31
  • 2
2
votes
0 answers

Django MPTTModel Tree structure gets corrupted inside Redis Cache upon concurrent creation and retrieval operations

Usecase: We've got a case where one of our models Content represents hierarchical data for our organization and for maintaining this hierarchy we've used django-mptt package which is based on the Modified Preorder Tree Transversal algorithm and for…
nick
  • 439
  • 1
  • 4
  • 17
2
votes
1 answer

How to serialize the django-mptt efficiently with Django Rest Framework?

serializers.py class RecursiveField(serializers.Serializer): def to_representation(self, value): serializer = self.parent.parent.__class__(value, context=self.context) return serializer.data class…
Jasmeet Pabla
  • 123
  • 10
2
votes
1 answer

'collections.OrderedDict' object has no attribute 'uuid' - Django REST Framework

I'm using django-mptt to create a tree-like structure for my Section model. Unfortunately, when I go to serialize it with drf-writable-nested, I get an error. This error only occurs when the url field is added to the serializer. Also, when I remove…
vit
  • 109
  • 1
  • 1
  • 9
2
votes
1 answer

Django MPTT - absolute url for category

I have the following tree structure: Cat 1 --Sub Cat 1 --Sub Cat 2 Cat 2 --Sub Cat 1 --Sub Cat 2 ----Subsub Cat 1 Using django-mptt I'm able to display this information using 1 query which is great, but when trying to create a url like:…
Hanpan
  • 10,013
  • 25
  • 77
  • 115