Open w0rp opened 8 years ago
I haven't tested this against all Django versions, but it should work on 1.8. I ran into this when I had a subclass of SearchQuerySet
, a manager which was a sub class of SearchManager
, and another sub class.
class MyBaseManager(SearchManager):
pass
class MyQuerySet(SearchQuerySet):
pass
class AnotherManager(MyBaseManager.from_queryset(MyQuerySet)):
pass
With the code as it is now, the get_queryset
method for AnotherManager
will return just an instance of SearchQuerySet
. With these changes here, it will return an instance of MyQuerySet
.
If the tests fail on older Django versions, it should be possible to detect the Django version and apply this patch differently by calling super()
with the attribute set in versions which support the attribute, and falling back on the current implementation of the method.
Overriding get_queryset causes problems when using
YourManager.from_queryset(YourQuerySetClass)
instead of return an instances ofYourQuerySetClass
, it will return an instance ofSearchQuerySet
. By changing the implementation of theSearchManager
class, you can support this use case, by not overriding theget_queryset
method so it will replace theBaseManager
method, so it can then return the correctQuerySet
subclass.