Use get_serializer_class in ordering filter by kmwenja · Pull Request #3487 · encode/django-rest-framework (original) (raw)
OrderingFilter
backend checks whether a view specifies anordering_fields
or serializer_class
attribute. Views can however
override get_serializer_class
to determine the serializer class
but the OrderingFilter
doesn't catch this. This patch fixes that.
Here's an example of a view that would benefit from this patch:
class MyView(generics.ListAPIView): queryset = MyModel.objects.all() filter_backends = (filters.OrderingFilter, )
def get_serializer_class(self):
return MySerializer
This would formerly raise an ImproperlyConfigured
error.