carljm/django-model-utils — pull request #79 by kezabelle (2013-09-16 20:07:13+00:00)
Title: Implementation for selecting subclasses by Model class rather than string.

This pull request constitutes the changes required to have #44 in as part of the InheritanceManager, without requiring a separate method API (which was what carljm favoured, when briefly floating the idea on IRC). It includes tests that indicate it seems to have equality parity with passing strings (or nothing) to `select_subclasses`. It does not include documentation as of yet.

The API now exposed is:
```
MyModel.objects.all().select_subclasses(MySubModel, AnotherSubModel)
```
The old API should still work:
```
MyModel.objects.all().select_subclasses()
MyModel.objects.all().select_subclasses('mysubmodel', 'anothersubmodel', 'yet__another__model')
```
As should mixing the two:
```
MyModel.objects.all().select_subclasses('mysubmodel', AnotherSubModel)
```

This is possibly not merge-ready, yet (not least because it needs squashing, and documentation), but I'm opening this for discussion on the implementation I've written, and to see if anyone can improve on it, because while it works, it doesn't feel the nicest.

It makes a few changes to the way select_subclasses is even implemented, in an attempt to validate mistakes, and it sorts the subclasses length-first, to guarantee that depth traversal can't be short circuited by a change in the order of `self.subclasses`.

All tests pass on 1.4.8, 1.5.4 and 1.6.0b3