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

how to collapse/expand a django-mptt list ideally using CSS and no JS in template

I need to collapse/expand a django-mptt list ideally using CSS (and no JavaScript) in my template: Following guidance from http://django-mptt.github.io/django-mptt/templates.html, I got a basic view, and have consulted the below SO…
kumarz
  • 451
  • 5
  • 10
2
votes
1 answer

Making a copy of a FeinCMS page tree using django-mptt changes child order

I'm trying to make a copy of a FeinCMS page tree, which is managed using django-mptt. I wrote this function: def make_tree_copy(page, parent=None): ''' Makes a copy of the tree starting at "page", reparenting it to "parent" ''' …
Jonas
  • 970
  • 1
  • 8
  • 17
2
votes
1 answer

Using django-mptt to get only the categories that have items

Sample structure: ALL UPPERCASE: Category Mixed Case: Item ROOT ├── BOOKS │   ├── FICTION │   │   └── CLASSICS │   └── NON-FICTION ├── CLOTHING └── ELECTRONICS ├── LAPTOPS ├── PHONES │   ├── APPLE │   │   ├── iPhone 6 │   │  …
Nick
  • 8,049
  • 18
  • 63
  • 107
2
votes
1 answer

Display detail page for model using django-mptt-urls

Im trying to access the detailpage of a photo instance, but I can't seem to get it to work. (The category detail page works great!) I would like to access http//domain.com/main-category/sub-cat/sub-sub-cat/photo-slug/ Models.py: from mptt.models…
Tomas Jacobsen
  • 2,368
  • 6
  • 37
  • 81
2
votes
2 answers

A node may not be made a child of any of its descendants in django mptt

here is the models.py class Category(MPTTModel): title = models.CharField(max_length =120) name = models.CharField(max_length=120) parent = models.ForeignKey('self' , null = True , blank = True , …
user6180320
2
votes
1 answer

Django-mptt initial migrations when using Django's Group model

I was having a look at django-mptt and found out that I can use use it with Django's built-in Group model. So, I followed the steps mentioned in documentation import mptt from mptt.fields import TreeForeignKey from django.contrib.auth.models import…
user3631116
2
votes
1 answer

Including foreign key count in django mptt full tree listing?

I'm spitting out my categories tree like so:
{% load mptt_tags %} {% full_tree_for_model bugs.Category as cats cumalative count bugs.Bug.categories %} {% for node, structure in cats|tree_info %} {% if structure.new_level…
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434
2
votes
1 answer

How do I filter for all descendants of a ForeignKey MPTT Model?

Here is the situation. I'm utilizing an MPTT Model in Django to create a hierarchy of music genres (Rock, Hard Rock, etc). I'm assigning one of the nodes of this hierarchy to an Album. Let's say I create a Album object with Hard Rock genre. How…
Ryan
  • 2,650
  • 3
  • 29
  • 43
2
votes
1 answer

How to get the depth level at a any given level in the template

Setup: a tree structure of the models. a representation of that structure in the HTML. Issue: How to know at any given recursion level the depth level at which currently I am? Example: This is the HTML:
  • 0
Diosney
  • 10,520
  • 15
  • 66
  • 111
2
votes
1 answer

How to populate inherited MPTT fields while creating a Django fixture?

I'm following the instructions here to create my first Django fixture. I've created a JSON file. But there is a complication: The model I'm trying to populate inherits from MPTTModel Here is what my Django JSON fixture file initial_data.json looks…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
2
votes
1 answer

How to build witt django-mptt a query joining to any descendant of mptt hierarchy element?

I want to build with django-mptt a hierarchy of vegetables classes (Fruit -> Berries -> Strawberry -> Douglas Strawberry) being the last level the variety. Retailer stocks are often related to the leaf level, the variety (Golden Apple, Douglas…
vokimon
  • 1,602
  • 1
  • 12
  • 9
2
votes
1 answer

Can't create many-to-many object in django admin using django-mptt

I can't create an object in django admin. It raises the error: ValueError at /admin/app/category/add/ "" needs to have a value for field "from_category" before this many-to-many relationship can be used. Request Method: GET Request URL: …
opportunity356
  • 168
  • 1
  • 11
2
votes
1 answer

django-mptt error on retrieving root nodes of a tree

I am trying to retrieve the root nodes of a hierarchy. My nodes look like this: class MyNode(MPTTModel): parent = TreeForeignKey('self', blank=True, null=True, related_name='children') slug =…
pkout
  • 6,430
  • 2
  • 45
  • 55
2
votes
2 answers

operational error - no such table - Django, mptt

I'm running into a DB related problem in Django that I don't understand. I define an MPTT model like so: class Image(MPTTModel): name = models.CharField(max_length=50) parent = TreeForeignKey('self', null=True, blank=True,…
David J.
  • 1,753
  • 13
  • 47
  • 96
2
votes
0 answers

Can django-mptt render a partial tree with ancestors and descendents from a subset of nodes?

Can django-mptt construct a partial tree from a list of nodes? Given this complete tree: Cars Automatic Truck Car Manual Truck Car Big-rig and given only a subset of nodes, let's say only ["Big-rig", "Car (automatic)"] can I…
Carson
  • 17,073
  • 19
  • 66
  • 87