Answer the question
In order to leave comments, you need to log in
How to get children of level n MPTTModel in django?
I am building a tree in django, connected mptt. The task is as follows: get all children at level n of their subtree (grandchildren-great-grandchildren). get_children().all(), as I understand it, returns children of the first level. We also need grandparents. I use self.parent.parent.parent... but I suspect there is a more concise way to achieve the result. We need instances / arrays of instances of the TreeNode class
class TreeNode(MPTTModel):
parent = TreeForeignKey('self', null=True, blank=True, related_name='child')
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question