Hello.
I am running official Django 1.2 and treebeard from the Mercurial repository. I also have the templates from treebeard listed in my templates directories.
I have the following model:
from treebeard.mp_tree import MP_Node
class ItemCategory(MP_Node):
title = models.CharField(max_length=100)
slug = models.SlugField(max_length=100, unique=True)
is_active = models.BooleanField(default=True)
node_order_by = ['title']
def __unicode__(self):
return self.title
When adding things in the interface, I will add like 2 categories. The first one is a child of root, and the 2nd one will be a child of the first.
However, when I do that, I notice that the display in the admin section only lists the first one. So I decided to see how it behaves on the command line. You will see the odd behavior here. I deleted all the objects from the command line then....
>>> ItemCategory.objects.all()
[]
>>> ItemCategory.add_root(title='CDs', slug='cds')
<ItemCategory: CDs>
>>> r = ItemCategory.objects.get(slug='cds')
>>> r
<ItemCategory: CDs>
>>> r.add_child(title='Music', slug='music')
<ItemCategory: Music>
>>> r = ItemCategory.objects.get(slug='cds')
>>> r.get_children()
[<ItemCategory: Music>]
# HERE I ADD A NEW ITEM "Instructional" IN THE ADMIN INTERFACE as a CHILD of "CDs"
>>> r = ItemCategory.objects.get(slug='cds')
>>> r.get_children()
[<ItemCategory: Music>]
So the item I add from the admin interface doesn't get properly added.
The database ends up looking like this.
}}}
#!SQL
mysql> select * from store_itemcategory;
+----+----------+-------+----------+---------------+---------------+-----------+
| id | path | depth | numchild | title | slug | is_active |
+----+----------+-------+----------+---------------+---------------+-----------+
| 8 | 00010001 | 2 | 1 | Music | music | 1 |
| 7 | 0001 | 1 | 1 | CDs | cds | 1 |
| 9 | 1 | 3 | 0 | Instructional | instructional | 1 |
+----+----------+-------+----------+---------------+---------------+-----------+
3 rows in set (0.00 sec)
Any idea why this happens? It seems like a bug. My models are simple and I'm on an official Django release.