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

Django: Best way for simple hierarchy?

I have this model: class Category(models.Model): name = models.CharField() description = models.CharField(blank=True) parent = models.ForeignKey('self', blank=True, null=True) I want Django to sort the categories with respect to their…
Someone
  • 33
  • 3
3
votes
0 answers

Adding a parent to django-mptt in Admin page throws an error

I had a model, which I changed to be MPTTModel, which looks like this class ServiceRequest(EntityBase, MPTTModel): parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True) field1 =…
GriMel
  • 2,272
  • 5
  • 22
  • 40
3
votes
2 answers

mptt with count of a different models instances that have tree model as foreignkey

In an online shop I use django-mptt for product categories with several levels. I also have products that each belong to a category. Now I'd like to visualise the category tree like this: all(18) - edible (10) -- food (4) -- drink (6) - inedible…
Amelse Etomer
  • 1,253
  • 10
  • 28
3
votes
1 answer

model_mommy breaks django-mptt

I'm using model_mommy to create instances of an MPTTModel in my tests, but it seems like it breaks the tree managed by mptt: >>> parent = mommy.make(Category) >>> child = mommy.make(Category, parent=parent) >>> parent.get_descendants() [] The same…
Martin Maillard
  • 2,751
  • 19
  • 24
3
votes
2 answers

Django: Hierarchical URLs

How do you deal with hierarchical URLs in Django? Any best practices for that? Eg. If I would have an URL like /blog/category1/category2/myblogentry (using eg. django-mptt), would you do some checking before in urls.py or give the whole path to a…
Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148
3
votes
2 answers

Overriding the save() method of a model that uses django-mptt

I've been using django-mptt in my project for a while now, it's fabulous. Recently, I've found a need to override a model's save() method that uses mptt, and I'm getting an error when I try to save a new instance of that model: Exception Type:…
saturdayplace
  • 8,370
  • 8
  • 35
  • 39
3
votes
2 answers

Django-mptt error. Can't find admin/mptt_change_list.html template

I\ve got a problem similar to this topic Django-MPTT, how to I've added 'mptt' to INSTALLED_APPS INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', …
opportunity356
  • 168
  • 1
  • 11
3
votes
1 answer

django-mptt: dealing with concurrent inserts

I have a threaded comment system which works fine 99.9% of the time, but very occasionally the tree breaks down and left/right values get duplicated. I have discovered that this happens when two posts happen at the same time (within a second of each…
meepmeep
  • 3,018
  • 7
  • 33
  • 47
3
votes
2 answers

ForeignKey to Django-MPTT tree generating storm of SQL requests in admin inline

I'm faced with a dramatic performance issue in connection with django-mptt. Here is my case: I have a Quizz class I have a Question class with a FK to Quizz and a FK to a Category class I have a Category class that is an MPTT tree (because my…
lai
  • 1,163
  • 10
  • 15
3
votes
0 answers

Django-CMS sometimes cannot publish a page

I have a site in Django-CMS 2.4.1. I often go into the admin panel and change a page there, e.g. dragging a plugin from one placeholder to another, or just change the details of a plugin. If I press "Publish draft" straight after this, I often get…
Racing Tadpole
  • 4,270
  • 6
  • 37
  • 56
3
votes
2 answers

Django-CMS warning on django-mptt

I have a Django-CMS 2.4.1 project that always gives me the warning: DeprecationWarning: Implicit manager CMSPlugin.tree will be removed in django-mptt 0.6. Explicitly define a TreeManager() on your model to remove this warning. This only occurs in…
Racing Tadpole
  • 4,270
  • 6
  • 37
  • 56
3
votes
1 answer

Django-mptt filter child from django template

I have used django-mptt to represent my hierarchical data. To get the data from database table I have used following code from my template. {% load mptt_tags %} {% recursetree nodes %} {{ node.name }} {% endrecursetree %} Now I want to filter…
Lahiruzz
  • 665
  • 1
  • 12
  • 24
3
votes
1 answer

How can I disable some options in the Select widget of a mptt's TreeForeignKey field in some model admin?

MyModel has a mptt's TreeForeignKey field category. In the admin of MyModel, how can I disable some options in the Select widget of this category field? Thanks you class Category(MPTTModel): parent = TreeForeignKey('self', blank=True, null=True,…
jul
  • 36,404
  • 64
  • 191
  • 318
3
votes
1 answer

I'm trying to build site navigation using django-mptt

I've used django-mptt to model the sections and sub-sections etc of the headings I want to store my articles under. Some sections and sections will have children others won't. eg: [Home] [News] [Politics][Crime][Policing] etc then [News] >…
Bill
  • 35
  • 6
3
votes
0 answers

django-mptt error with existing model

I already have model topic and have data in it, when I tried to use MPTTMODEL insted of the regular model class Topic(MPTTModel): parent = TreeForeignKey('self', null=True, blank=True, related_name='children') .... so I run the following…
Kareem Hashem
  • 1,057
  • 1
  • 9
  • 25