Lets say I have this class (simplified):
class Tag (...):
children = models.ManyToManyField(null=True, symmetrical=False)
Now I already implemented the functions get_parents, get_all_ancestors. Is there a nice pythonic way to just the top level tags? If I had designed my Tags differently (to point to the parents instead) I would just make get_all_parents().filter(children=None)
.
My first thought is to create a new function that will go recursively through all parents and save those that has none.
But is there a possibility with filters or Query-objects to do the same (with fewer lines of code)?
Thanks for your help.
[edit]
When it is finished, it should be a hierarchical tagging system. Each tag can have children, parents, but only the children are saved. I want to get all the top level tags, that point through many children / childrens children to my tag.