Francisco
Francisco

Reputation: 11496

How do I filter for leaf nodes in an MP_NODE

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.

Upvotes: 0

Views: 784

Answers (1)

Francisco
Francisco

Reputation: 11496

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)

Upvotes: 2

Related Questions