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
1
vote
2 answers

What's my mistake in doing the following in django-mptt?

I have a category tree, with Items entry related to the category. So this is my model file: from django.db import models import mptt class Category(models.Model): nombre=models.CharField(max_length=70) padre=models.ForeignKey('self', blank=True,…
Ezequiel
  • 668
  • 2
  • 9
  • 25
1
vote
1 answer

Query with difficult conditions in the project using mptt

I have some mptt model: class Locations(MPTTModel): parent = TreeForeignKey('self', null=True, blank=True, related_name='children') type = models.ForeignKey('LocationTypes') title = models.CharField(max_length=100) Some models related…
Atterratio
  • 445
  • 2
  • 9
  • 25
1
vote
1 answer

Ordering mptt tree using a field

This is the original category model: class Category(MPTTModel): name = models.CharField(max_length=50, unique=True) parent = TreeForeignKey('self', null=True, blank=True, related_name='children') def __unicode__(self): return…
Adam
  • 2,948
  • 10
  • 43
  • 74
1
vote
0 answers

using tastypie django-mptt's parent_id field becomes NULL during POST

I would like to build the following tree: top: son1 son2 using mptt django tastypie (see bellow the following model and resource code). instead of creating two children to the 'Top' record, it creates two trees (different tree_id) and the…
Joe
  • 11
  • 3
1
vote
1 answer

Select children when parent selected in TreeNodeMultipleChoiceField

I'm using django-mptt in my project. Form is: class UserSettingsForm(forms.ModelForm): category = TreeNodeMultipleChoiceField( required=True, queryset=NewsCategory.objects.all(), label=u"category", …
TheNone
  • 5,684
  • 13
  • 57
  • 98
1
vote
2 answers

Django different forms for admin model

Is there any way to load different admin forms for editing an objects depending of what object is needed to be updated? For example - we have an MPTTModelAdmin objects. And for root objects we don't want to see some fields: class…
1
vote
1 answer

Trouble using django-mptt for nested comment system

I'm trying to set up a simple nested comment system using django-mptt, but I'm running into a few issues. If someone could take a look and tell me what I'm doing wrong, I would be really grateful. So far, I've only set up the display of comments for…
1
vote
1 answer

MPTT order DESC

I'm trying to create a comment system on my site. I'm using MPTT tree model and Django. Basically I would like to show the most recent post on top. When I try : order_insertion_by=['-creation_date'] I get this error : Comment has no field named…
flo bee
  • 830
  • 2
  • 11
  • 20
1
vote
0 answers

Parsing a Django-mptt JSON

I have created created a dictionary from Django-mptt and used json.dump() to get the JSON object. { "a": "cat1", "c": ["item2", "item1"], "b": [ {"a": "burgers", "c": [], "b": []}, {"a": "south indian", "c": [], "b": []}, {"a":…
1
vote
1 answer

Error that field is required when there is no field empty

This is my view: class EditInventoryView(UpdateView): model = Inventory form_class = InventoryForm template_name = 'inventory/detail.html' def get(self, request, **kwargs): object = super(EditInventoryView,…
Naftali
  • 144,921
  • 39
  • 244
  • 303
1
vote
1 answer

Creating child records with django-mptt

I have successfully completed the django-mptt tutorial. What I cannot figure out how to do is create a child of a child. By child of a child, i mean a third level deep and more. See example below, I want to create 1.3.1, 1.3.2, 1.3.1.1 1.0 Product…
James
  • 815
  • 1
  • 13
  • 24
1
vote
1 answer

Django MPTT - how expensive is objects.rebuild?

I will roll out in the next days an application which is using Django MPTT to manage hierarchical data. MPTT provides a function called rebuild, which rebuilds all trees available for a given model, and is called as such TreeNodes.objects.rebuild().…
Thomas Kremmel
  • 14,575
  • 26
  • 108
  • 177
1
vote
1 answer

Django MPTT Giving DatabaseError When Saving

I have installed MPTT for Django, put it in "installed apps," set up my files, and synced my database. My model shows in admin, but when I click save after trying to add a category I get the following error: DatabaseError at…
1
vote
1 answer

Cumulative count in recoursetree?

Using django-mppt I want to browse my category hierarchy displaying the ammount of objects related to the current category in any of it's children. Much like drill_down_for_node in the example shown, but only with the current node childrens... The…
tutuca
  • 3,444
  • 6
  • 32
  • 54
1
vote
1 answer

Access get_root of a MPTT model through a query

Consider below example: class ModelX(models.Model): fieldX = models.ForeignKey(ModelY) class ModelY(MPTTModel): def root(self): return get_root() root = property(root) Now I would like to make query like…
Milo Wielondek
  • 4,164
  • 3
  • 33
  • 45