Open jukanntenn opened 2 years ago
This would certainly be doable; the problem is that django-tree-queries doesn't add much API at all. It has almost no extension points. What you write would probably be more straightforward to implement on top of a more generic solution for building CTEs, maybe https://pypi.org/project/django-cte/
django-mptt
has a featureget_queryset_descendants
which query the descendants of tree nodes represented by a queryset. However,TreeQuerySet.descendants
method in django-tree-queries only support query descendants of a certain tree node. After doing some experiments, I find a way to implement such feature, like bellow:The idea is if
of
parameter is a queryset rather than a single model instance, changing the where clause to or.The downside of this approach is we need an extra database query. I also have no idea if there is performance issue for a large queryset.
Another idea I come up with is inject a a subquery in CTE, like bellow: change:
to:
but I also have no idea that this is feasible.