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
0 answers

Django: can't delete item in Model inherting django-mptt

in models.py, i've the following code: import uuidfrom django.db import modelsfrom django.db.models import Qfrom mptt.models import MPTTModel, TreeForeignKey from company.models import Account class Plan(MPTTModel): id = …
0
votes
0 answers

mptt not linking children and parent - Django

I'm having an issue that I seriously can't wrap my head around. I am using Django MPTT models and evrerything seems to be working fine (i.e. I can run the migrations and insert data in the database), but for some reason the TreeForeignKey table…
ETisREAL
  • 90
  • 1
  • 2
  • 9
0
votes
0 answers

Mptt model does not return {{ children }}

I have a Deviz model that inherits from MPTTmodel. I populated the database with data but can't get to show the children. The tree should be like this: Chapter 1 -Subchapter 1 --SubSubchapter 1 ---Article 1 …
0
votes
2 answers

how to display subcategories title and its items under parent category in django?

I want to display subcategories title and its items under parent category in Django e.g. I have 1 parent category then it hast 2 sub cats and then each of them has 3 sub cats. in every sub category there are 10 items. Parental…
0
votes
0 answers

How can get selected item from auto fields on many to many relationship (django Admin Model)

I'm new in django. I want to create several sub-categories with django-mptt, and on the Django management page, when creating a product, the main categories will be searched first, then searched subcategories under selected main category, and so…
S F
  • 1
0
votes
1 answer

Django mptt returns -2 on get_descendant_count()

I am trying to get the descendants of a root node, but for some reason the function returns -2 on get_descendant_count(). Here's the code: roots = Project.tree.root_nodes() print(roots[0].get_descendants()) // returns…
mgPePe
  • 5,677
  • 12
  • 52
  • 85
0
votes
1 answer

How to optimize N+1 SQL queries when serializing a post with mptt comments?

I have the following serializer for a detailed post: class ArticleDetailSerializer(serializers.ModelSerializer): author = ArticleAuthorSerializer(read_only=True) comments = CommentSerializer(many=True, read_only=True) class Meta: …
Razilator
  • 75
  • 5
0
votes
0 answers

how to convert tree query set into dictionary?

book_category_list=[] for book_category in BookCategory.objects.filter(parent__isnull = True): book_category_list.append(book_category.get_family())** now the book_category_list in tree query set format. I need to list categories in a tree…
Rahman
  • 1
0
votes
1 answer

How to link hierarhical data into another model in Django?

Consider the following hierarchical data. It can be 3 to 4 levels deep. I understand I can use existing packages like django-mptt or django-treebeard to create a tree data…
user4979733
  • 3,181
  • 4
  • 26
  • 41
0
votes
1 answer

Change DjangoMPTT admin model name

I have the following MPTTModel and admin.py: class Category(MPTTModel): name = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='children') def…
static-man
  • 29
  • 7
0
votes
1 answer

Django mptt Multiple references to class objects

I need to make a model for spices. Some spices may consist of others, or be basic. I need something like TreeForeignKey with multi-select option. I tried to use TreeManyToManyField, but I can't set null for base spices there. Here is my code: class…
0
votes
0 answers

Bulk import with mptt, django and csv

I have the following code to take data from a very large csv, import it into a Django model and convert it into nested categories (mptt model). with open(path, "rt") as f: reader = csv.reader(f, dialect="excel") next(reader) …
megler
  • 217
  • 1
  • 2
  • 9
0
votes
0 answers

How can i redirect url without trailing slash to one with trailing slash

I've got this code def category_view(request, path, instance): if instance is not None: categories = instance.get_ancestors(include_self=True) category_descendants = instance.get_descendants(include_self=True) product =…
Jakobkubek
  • 77
  • 1
  • 6
0
votes
1 answer

Django MPTT Queryset to nested dictionary without recursive calling

The Django MPPT is smart library that make only single query to get all nested data. Is there a way to get the data as nested dictionary without recursive calling. queryset = MyTreeModel.objects.values() results = get_nested_dict(queryset)…
AlASAD WAIL
  • 775
  • 4
  • 18
0
votes
1 answer

django mptt tag recursetree => is there any counter like forloop.counter or we have to declare a counter variable

We have forloop.counter for iteration in django template this is a built-in template operation. Using this loop counter we can display the number and also utilize for various decisions of color or odd/even etc., UI work. similarly, I am utilizing…
ARUN RG
  • 1
  • 1