Let's say I have these Models:
class Category(MP_Node):
name = models.CharField(max_length=30)
class Item(models.Model):
category = models.ForeignKey(Category)
and I would like to find all Items belonging to any descendant of a given Category.
Usually I would write category.item_set but this is just Items belonging to the given level of the hierarchy.
Using the example tree in the treebeard tutorial, if an Item belongs to "Laptop Memory", how would I find all Items belonging to descendants "Computer Hardware" where "Laptop Memory" is one of those descendants?
For example, you can get all descendants of a category with get_descendants() in
views.pyas shown below. *You can see my answer explaining how to get all descendants of a category including the model instance itself withget_descendants(include_self=True):