from django_ltree.fields import PathValue
from django_ltree.managers import TreeManager, TreeQuerySet
[docs]class AkvoTreeQuerySet(TreeQuerySet):
[docs] def descendants(self, path: PathValue, with_self=False) -> "AkvoTreeQuerySet":
queryset = self.filter(path__descendants=path)
if not with_self:
queryset = queryset.exclude(path=path)
return queryset
[docs]class AkvoTreeManager(TreeManager):
[docs] def get_queryset(self):
return AkvoTreeQuerySet(model=self.model, using=self._db).order_by("path")
[docs] def descendants(self, path: PathValue, with_self=False) -> AkvoTreeQuerySet:
return self.filter().descendants(path, with_self=with_self)