brack3t/django-braces — pull request #149 by dbaty (2014-09-15 09:30:06+00:00)
Title: Do not blindly override select_related or prefetch_related.

Currently, when empty `select_related` or `prefetch_related` attributes are given to subclasses of `SelectRelatedMixin` and `PrefetchRelatedMixin`, these mixins issue an empty call to `select_related()` and `prefetch_related()`. Up to Django 1.6 (included), these calls are not chainable. Hence, if the original queryset already has select_related or prefetch_related fields, the mixins cancel them.

Use case: we have a custom ListView that inherits from SelectRelatedMixin. Most subclasses define a queryset with no select_related or with a custom one through a `select_related` attribute. This is fine. However, for some other views, we re-use a manager that does the right select_related (keeping the definition of select_related fields in a single place) :

class CustomListView(ListView, SelectRelatedMixin):
queryset = Article.objects.with_list_select_related()

class ThingListView(CustomListView):
queryset = Thing.objects.list_select_related()