How to get all objects with their children using django orm?
- by kender
Hi,
I got very simple hierarchical structure: every object can have 0 or 1 parent. There's no limit on how many children each object can have.
So in my application I got such a model:
class O(Model):
name = CharField(max_length = 20)
parent = ForeignKey('O', related_name = 'children')
Now I would like to be able to fetch all objects who have a particular one Object1 in their parent-tree (as in their parent or parent of their parents, etc).
Should I use mptt or is there a simpler approach?