diff --git a/docs/api-guide/filtering.md b/docs/api-guide/filtering.md index 7e99832ee..a710ad7dd 100644 --- a/docs/api-guide/filtering.md +++ b/docs/api-guide/filtering.md @@ -216,7 +216,7 @@ For more details, see the [Django documentation][search-django-admin]. ## OrderingFilter -The `OrderingFilter` class supports simple query parameter controlled ordering of results. For example: +The `OrderingFilter` class supports simple query parameter controlled ordering of results. To specify the result order, set a query parameter named `'order'` to the required field name. For example: http://example.com/api/users?ordering=username diff --git a/rest_framework/filters.py b/rest_framework/filters.py index 308e7da2c..6a3e055d4 100644 --- a/rest_framework/filters.py +++ b/rest_framework/filters.py @@ -112,7 +112,7 @@ class SearchFilter(BaseFilterBackend): class OrderingFilter(BaseFilterBackend): - ordering_param = 'order' # The URL query parameter used for the ordering. + ordering_param = 'ordering' # The URL query parameter used for the ordering. def get_ordering(self, request): """ diff --git a/rest_framework/tests/filters.py b/rest_framework/tests/filters.py index 6b604deb1..b20d59805 100644 --- a/rest_framework/tests/filters.py +++ b/rest_framework/tests/filters.py @@ -369,7 +369,7 @@ class OrderingFilterTests(TestCase): ordering = ('title',) view = OrderingListView.as_view() - request = factory.get('?order=text') + request = factory.get('?ordering=text') response = view(request) self.assertEqual( response.data, @@ -387,7 +387,7 @@ class OrderingFilterTests(TestCase): ordering = ('title',) view = OrderingListView.as_view() - request = factory.get('?order=-text') + request = factory.get('?ordering=-text') response = view(request) self.assertEqual( response.data, @@ -405,7 +405,7 @@ class OrderingFilterTests(TestCase): ordering = ('title',) view = OrderingListView.as_view() - request = factory.get('?order=foobar') + request = factory.get('?ordering=foobar') response = view(request) self.assertEqual( response.data,