I have a list of category pages obtained as follows:
category_ids = request.GET.getlist('category[]')
category_pages = MyCategoryPage.objects.filter(pk__in=category_ids)
What I'd like to do is refine a list of pages to include only those that are children of the categories specified above.
I'm aware that you can do this for one object as follows:
pages = MySubPage.objects.child_of(category)
..but as far as I can tell there is no way to do child_of(category_pages) for more than one parent.
In normal Django, where I'd probably have a category ForeignKey on MySubPage, I'd just do:
pages = MySubPage.objects.filter(category__in=filter_categories)
..but again I'm not sure that I can do that in Wagtail.
I know I could probably loop through all the categories and append the sub pages to a list:
pages = []
for category in category_pages:
pages.append(MySubPage.objects.child_of(category))
...and then join them all, but that doesn't seem very efficient and obviously it would return a list rather than a queryset.
I've searched the docs but can't find any more direct way of achieving this.