(queryset=None)
return queryset.model.objects.filter(Q(id__in=queryset.values_list('id')) | ancestors)
:param queryset: Model Queryset to add ancestors
        :param filter: Filter (include) the ancestors nodes with the provided Q filter
:param queryset: Model Queryset to add ancestors
        :param filter: Filter (include) the ancestors nodes with the provided Q filter
: param queryset : Model Queryset to add ancestors : param filter : Filter ( include ) the ancestors nodes with the provided Q filter
def include_ancestors(queryset=None):
        """
        :param queryset: Model Queryset to add ancestors
        :param filter: Filter (include) the ancestors nodes with the provided Q filter
        """

        queryset = queryset.annotate(root=Substr('path', 1, queryset.model.steplen))
        nodes = list(set(queryset.values_list('root', 'depth')))

        ancestors = Q()
        for node in nodes:
            ancestors |= Q(path__startswith=node[0], depth__lt=node[1])
        return queryset.model.objects.filter(Q(id__in=queryset.values_list('id')) | ancestors)
def include_ancestors ( queryset = None ) : queryset = queryset . annotate ( root = Substr ( 'path' , 1 , queryset . model . steplen ) ) nodes = list ( set ( queryset . values_list ( 'root' , 'depth' ) ) ) ancestors = Q ( ) for node in nodes : ancestors |= Q ( path__startswith = node [ 0 ] , depth__lt = node [ 1 ] ) return queryset . model . objects . filter ( Q ( id__in = queryset . values_list ( 'id' ) ) | ancestors )