0

I have a tree model for categories like this:

from treebeard.mp_tree import MP_Node

class Category(MP_Node):
    ...

And I want to get a queryset with only the leaf nodes.

Francisco
  • 10,918
  • 6
  • 34
  • 45

1 Answers1

1

MP_Node has a field called numchild, which stores the amount of children each node has, so you can get a queryset of all leaf nodes like this:

Category.objects.filter(numchild=0)
Francisco
  • 10,918
  • 6
  • 34
  • 45