dabapps / django-readers

A lightweight function-oriented toolkit for better organisation of business logic and efficient selection and projection of data in Django projects.
https://www.django-readers.org
BSD 2-Clause "Simplified" License
183 stars 7 forks source link

SpecMixin now overrides get_queryset, not filter_queryset #53

Closed j4mie closed 2 years ago

j4mie commented 2 years ago

filter_queryset is specifically part of REST framework's generic filtering interface, and so using it as the point where the SpecMixin "hooks in" and applies the prepare function was a bit weird. Instead, we now override get_queryset, which is simpler and more idiomatic.

This also fixes a bug: if you were using OrderingFilter but your spec also contained a pair whose prepare function orders the queryset in some way, then previously the OrderingFilter didn't have any effect, because SpecMixin's filter_queryset happened after the base filter_queryset was called. Now, because we no longer override filter_queryset, the OrderingFilter is able to do its stuff to the already-prepared queryset.