def qs_ancestors(queryset):
    if isinstance(queryset, EmptyQuerySet):
        return queryset
new_queryset = queryset.none()
for obj in queryset:
    new_queryset = new_queryset | obj.get_ancestors()
return new_queryset
efficient function to retrieve a queryset of ancestors of an mptt queryset