I have two models, ParentPage
and ChildPage
. I want to find the set of ParentPage
s where a field is_completed
is True
on the ChildPage
.
Normally in Django, I could do something like
ParentPage.objects.filter(child_page__is_completed=True)
However, I don't think there is a join here for the Wagtail/Treebeard hierarchy.
I also thought you might be able to filter ChildPage
s by multiple ParentPage
s, e.g. ChildPage.objects.children_of([parent_ids])
, but I can't see a way to do that either.
Is there a simpler way?
The Page table has
path
andurl_path
columns. If you find all children and strip the last part of thepath
orurl_path
, you can use that result to query the parent pages.Path:
Url path:
Disclaimer: untested code.