min_obj_set = []
for obj in queryset.order_by('tree_id', '-level'):
    for obj2 in min_obj_set:
        if obj.is_ancestor_of(obj2):
            break
else:
    min_obj_set.append(obj)
efficient function to retrieve a queryset of ancestors of an mptt queryset