django-mptt/django-mptt — pull request #300 by musashiXXX (2014-04-11 16:32:01+00:00)
Title: get_queryset_ancestors

This method is similar to ``get_queryset_descendants`` only it works in the opposite direction. You may be wondering "What's the point? Why can't you use get_ancestors()?" What if you wanted to filter a queryset using characteristics of its descendants to determine the results of the filter?

Here's an example of such a query using files and directories arranged in the usual hierarchical fashion that we're all familiar with. In this scenario we are determining whether a user has access to a directory based off of the content, or _type_ of file or files that exist within said directory. So we start with this:

``>>> Directory.objects.filter(file__filetype__accessible_filetypes__users = 1)
[, >> Directory.tree_manager.get_queryset_ancestors(Directory.objects.filter(file__filetype__accessible_filetypes__users = 1))
[, ]``

Now we have queryset of intermediate directories that we can filter even further:

``>>> Directory.tree_manager.get_queryset_ancestors(Directory.objects.filter(file__filetype__accessible_filetypes__users = 1)).filter(parent = 1)
[]``