parameters: (queryset=None)
return_statement: return queryset.model.objects.filter(Q(id__in=queryset.values_list('id')) | ancestors)
docstring: :param queryset: Model Queryset to add ancestors
          :param filter: Filter (include) the ancestors nodes with the provided Q filter
docstring_summary: :param queryset: Model Queryset to add ancestors
          :param filter: Filter (include) the ancestors nodes with the provided Q filter
docstring_tokens: : param queryset : Model Queryset to add ancestors : param filter : Filter ( include ) the ancestors nodes with the provided Q filter
function: 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)
function_tokens: 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 )