I'm using django-mptt 0.4.2 and have trouble with one of my data trees.
Here is the tree as seen in mysql;
mysql> select id, lft,rght,level from my_object where tree_id=30613;
+-------+-----+------+-------+
| id | lft | rght | level |
+-------+-----+------+-------+
| 89919 | 1 | 10 | 0 |
| 89924 | 10 | 11 | 1 |
| 89930 | 6 | 9 | 1 |
| 90401 | 2 | 5 | 1 |
| 90406 | 3 | 4 | 2 |
| 90407 | 7 | 8 | 2 |
+-------+-----+------+-------+
In my Python shell it looks the same:
>>> obj = MyObject.objects.filter(tree_id=30613)
>>> for o in obj:
... print "%5d %2d %2d %1d" % (o.id, o.lft, o.rght, o.level)
...
89919 1 10 0
89924 10 11 1
89930 6 9 1
90401 2 5 1
90406 3 4 2
90407 7 8 2
The problem is when I use the .get_descendants() method from django.mptt:
>>> parent_node = MyObject.objects.get(id=89919)
>>> descendants = parent_node.get_descendants()
>>> for o in descendants:
... print "%5d %2d %2d %1d" % (o.id, o.lft, o.rght, o.level)
...
90401 2 5 1
90406 3 4 2
89930 6 9 1
90407 7 8 2
>>> print descendants.query # Formatted for readability
SELECT * FROM `my_obj`
WHERE (
`my_obj`.`lft` <= 9
AND `my_obj`.`lft` >= 2
AND `my_obj`.`tree_id` = 30613
) ORDER BY `my_obj`.`tree_id` ASC, `my_obj`.`lft` ASC
Why doesn't django-mptt retrieve all the descendants?