views:

112

answers:

0

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, null=True)

 def __unicode__(self):
  return self.nombre

 class Meta:
  ordering = ['tree_id', 'lft']

# Create your models here.

class Item(models.Model):
    category=models.ManyToManyField(Category)

try:
 mptt.register(Category, order_insertion_by=['nombre'], parent_attr='padre')
except mptt.AlreadyRegistered:
 pass

I'm using ManyToManyField because each item can be in more than one category.

Now, after installing 'mptt' in my apps. I'm trying the following in the shell:

Category.tree.add_related_count(Category.tree.root_nodes(), Item,
    'category', 'q_c', cumulative=True)

Which should return a tree, and load the number of Items belonging to a node on each node. This seems like standard functionality of django-mptt as stated in the documentation.

However, I get an error. The following is the trace:

http://pastebin.com/m69ed1937

Using SVN django-mptt and django 1.1 in Ubuntu 9.1.