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

Re-ordering child nodes in django-MPTT

I'm using Ben Firshman's fork of django-MPTT (hat tip to Daniel Roseman for the recommendation). I've got stuck trying to re-order nodes which share a common parent. I've got a list of primary keys, like this: ids = [5, 9, 7, 3] All of these nodes…
Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
7
votes
1 answer

Django-mptt model serialize with Django REST framework

I have used django-mptt to store categories hierarchy and I need to serialize all category data in below format. { "id": 1, "name": "FOOD" "children": [ { "id": 6, …
Jay Modi
  • 3,161
  • 4
  • 35
  • 52
7
votes
2 answers

Django MPTT efficiently serializing relational data with DRF

I have a Category model that is a MPTT model. It is m2m to Group and I need to serialize the tree with related counts, imagine my Category tree is this: Root (related to 1 group) - Branch (related to 2 groups) - Leaf (related to 3…
WBC
  • 1,854
  • 4
  • 21
  • 34
7
votes
1 answer

Django-mptt completely buggy or am I doing it wrong?

I'm attempting to use django-mptt with very little luck. This is with Python2.5, windows, sqlite3, Django 1.2pre , django-mptt latest from svn. The code: model: class Node(models.Model): name = models.CharField(max_length=20, blank=True) …
Parand
  • 102,950
  • 48
  • 151
  • 186
7
votes
2 answers

How to serialize hierarchical relationship in Django REST

I have a Django model that is hierarchical using django-mptt, which looks like: class UOMCategory(MPTTModel, BaseModel): """ This represents categories of different unit of measurements. """ name = models.CharField(max_length=50,…
7
votes
0 answers

How to change parent of a node in django-mptt

I m using django-mptt (Ver 5.5) django-mptt.github.io/django-mptt/ I have a tree structure as: +Object Oriented |----Java +Procedural |----Python |----PHP |----B |----C now i want to restructure the tree , by changing the parent of Python and PHP…
akm
  • 79
  • 2
6
votes
4 answers

Why can't I save my model instances after editing them?

I have a model which I can instantiate just fine, but once created, if I attempt to save it I get an IntegrityError saying that the primary key must be unique. What's causing this? There are other models that inherit from Node, and they're giving…
Jackie
  • 61
  • 1
  • 3
6
votes
1 answer

Storing hierarchical (parent/child) data in Python/Django: MPTT alternative?

I'm looking for a good way to store and use hierarchical (parent/child) data in Django. I've been using django-mptt, but it seems entirely incompatible with my brain - I end up with non-obvious bugs in non-obvious places, mostly when moving things…
Parand
  • 102,950
  • 48
  • 151
  • 186
6
votes
1 answer

Acyclic graph in Django

I would like to achieve acyclic graph structure in Django. For example I have some categories in tree structure: Guitars - Classical Guitars - Western Guitars - Guitars for Children Ukuleles - Soprano Ukulele - Concert Ukulele - Baryton Ukulele -…
Tom Tichý
  • 1,065
  • 1
  • 12
  • 19
6
votes
3 answers

Wrong results when use `get_ancestors` functions from `django-mptt`

I'm developing a project which uses django-mptt, but I get strange results when I use get_ancestors function. Here is an example. I have a created a simple model, inherited from MPTTModel: class Classifier(MPTTModel): title =…
idea.list
  • 145
  • 3
  • 5
5
votes
1 answer

How to order django-mptt tree by DateTimeField?

This is the model I am using: class Comment(MPTTModel): comment = models.CharField(max_length=1023) resource = models.ForeignKey('Resource') created_at = models.DateTimeField(auto_now_add=True) parent = TreeForeignKey('self',…
WSkinner
  • 2,147
  • 1
  • 19
  • 21
5
votes
2 answers

Django-MPTT - ordering root nodes by count of immediate descendants

I'm using Django-MPTT to do a display a simple 2 level hierarchy (root => child(ren)). I'm looking for a way to structure my queryset so that nodes get returned with the root node having the most children first and the node with the least children…
NFicano
  • 1,065
  • 1
  • 11
  • 26
5
votes
5 answers

Django-MPTT, how to

Hey, I have just installed the django-mptt lib, but i don't know how to get it to work :( I have added from mptt.models import MPTTModel class Category(MPTTModel): slug = models.SlugField(max_length=200, unique=True) name =…
pkdkk
  • 3,905
  • 8
  • 44
  • 69
5
votes
2 answers

Is it possible to integrate django-taggit and django-mptt / django-treebeard?

I am developing a website that requires tagging up different types of content, which favors using django-taggit. But, it would be extremely beneficial if the tags were represented in the database in their natural hierarchy, favoring use of…
5
votes
2 answers

How to serialize a Django MPTT family and keep it hierarchical?

I was trying to find solution for this (Google cache) And I could only came up with a solution like this: import json from mptt.utils import tree_item_iterator from rest_framework import generics from rest_framework.response import Response from…
diogosimao
  • 163
  • 2
  • 9
1
2
3
23 24