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

Django MPTT Filter Only if No Children Exist

So I am using MPTT for a Category model in Django, and I was wondering if there is a way to filter a Category if there is no child. models.py: class Category(MPTTModel, TimeStampedModel): title = models.CharField(max_length=75) parent =…
Hybrid
  • 6,741
  • 3
  • 25
  • 45
0
votes
0 answers

How to delete from binarytree data and upgrade descendents ? django-mptt

im trying a same days to solve, but i cant image the algorithm for this. for example have a binary tree. # [1] # [2] [3] # [4] [5] [6] [7] # [8][9][10][11] [12][13][14][15] im need to delete…
Softsofter
  • 345
  • 1
  • 3
  • 13
0
votes
1 answer

Django ORM - building hierarchical data structure with multiple models

as a part of a project I'm working on, I'm trying to build an hierarchical data structure of objects from different types. I used django-mptt for it, which promises to handle trees in a smart way with fast queries. The problem is, that I have…
0
votes
1 answer

Django Rest Framework list_route and queryset on tree structure

Trying to display hierarchy of categories through DRF serializer and it fails GET /api/mobile/v1/categories/tree/ HTTP/1.1 Host: localhost:8000 Accept: application/json Content-Type: application/json Cache-Control: no-cache Postman-Token:…
0
votes
1 answer

Django MPTT queryset for instances with children with a certain attribute

I'm using Django MPTT, with the model Foobar like this: class Foobar(MPTTModel): parent = TreeForeignKey('self', null=True, blank=True, related_name='children') If I want to select all Foobars with children, I can do this: [x for x in…
Flimm
  • 136,138
  • 45
  • 251
  • 267
0
votes
1 answer

Django, detect if model field is inherited

I'd like to check if a model field is inherited, similar to Field.is_relation. Is there a way to tell? I have a model that inherits from MPTTModel and I want a list of the attributes defined directly in the model but not in MPTTModel. E.g.: #…
James H.
  • 99
  • 11
0
votes
1 answer

django-mptt show "no such column"

I used MPTT to implement a forum which allow posts to latest news.I can't solve this error: "no such column: news_comment.lft" The app name is news.This is models.py: from django.db import models from mptt.models import MPTTModel,…
ross
  • 1
  • 2
0
votes
0 answers

Hide field when parent.level is lower then 5?

How can i hide a field "content", when parent level is lower then 5 in mptt.django ? I want edit a field when descendent is 5. class Menu(MPTTModel): name = models.CharField(max_length=50, blank=True, null=True) content =…
Emil
  • 1
  • 1
0
votes
1 answer

How to show only first level child when second level child doen't exists otherwise show second level child in django MPTT

I got following output from django-mptt tree: Group-2 Ministry E Division G Division Z Ministry F Division I Division J Group-3 Ministry P Division X Division Y Ministry Q …
ohid
  • 824
  • 2
  • 8
  • 23
0
votes
1 answer

django-mptt raises 'NoneType' object has no attribute 'tree_id' when saving node

Environment: python 2.7.10, Django 1.9.1, django-mptt 0.8.4 # models.py class Foo(MPTTModel): parent = TreeForeignKey('self', null=True, blank=True) Error raises in: getattr(self, opts.tree_id_attr) != getattr(parent, opts.tree_id_attr) where…
0
votes
0 answers

Django- How to get mptt children in template

The closest thing that I could find to my questions is this. I have the following model: class Specialty(models.Model): name = models.CharField(max_length=128) class Meta: verbose_name_plural = 'Specialties' def…
mjr
  • 97
  • 2
  • 11
0
votes
1 answer

Advanced URLs in Django

The task is to write two url patterns. The first one will take a single argument , which can be any url with random depth: test/dorogi/ or test/foo/bar/as/deep/as/you/want The second one will be the same as the first one, but with a number in…
Viktor
  • 4,218
  • 4
  • 32
  • 63
0
votes
1 answer

Show select as a tree

How to show categories as a tree in Django admin using MPTT? I made it show list of categories as a tree: But it does not work when I try to create a new article: How do I make it render select as a tree? Here is my model: # -*- coding: utf-8…
Viktor
  • 4,218
  • 4
  • 32
  • 63
0
votes
1 answer

global name from django-mptt is not defined

So it must be something basic but I cant figure it out . I am trying to use django-mptt just following the tutorial created in models.py @with_author class Tree(MPTTModel): name = models.CharField(max_length=50, unique=True) parent…
Ilya Bibik
  • 3,924
  • 4
  • 23
  • 48
0
votes
0 answers

get_family not returning entire family of root node in mptt

I am using django mptt for tree structure. I ma adding parent to any object while updating not creating any object as shown below . user= User.objects.create(username='abc') after some logics or steps when we are sure that it can be added as a…
user5594493
  • 1,050
  • 3
  • 10
  • 24