mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-30 05:24:00 +03:00
Added OrderingFilter
This commit is contained in:
parent
6a037f63ed
commit
2cff6e69db
|
@ -216,7 +216,7 @@ For more details, see the [Django documentation][search-django-admin].
|
||||||
|
|
||||||
## OrderingFilter
|
## 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
|
http://example.com/api/users?ordering=username
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ class SearchFilter(BaseFilterBackend):
|
||||||
|
|
||||||
|
|
||||||
class OrderingFilter(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):
|
def get_ordering(self, request):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -369,7 +369,7 @@ class OrderingFilterTests(TestCase):
|
||||||
ordering = ('title',)
|
ordering = ('title',)
|
||||||
|
|
||||||
view = OrderingListView.as_view()
|
view = OrderingListView.as_view()
|
||||||
request = factory.get('?order=text')
|
request = factory.get('?ordering=text')
|
||||||
response = view(request)
|
response = view(request)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.data,
|
response.data,
|
||||||
|
@ -387,7 +387,7 @@ class OrderingFilterTests(TestCase):
|
||||||
ordering = ('title',)
|
ordering = ('title',)
|
||||||
|
|
||||||
view = OrderingListView.as_view()
|
view = OrderingListView.as_view()
|
||||||
request = factory.get('?order=-text')
|
request = factory.get('?ordering=-text')
|
||||||
response = view(request)
|
response = view(request)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.data,
|
response.data,
|
||||||
|
@ -405,7 +405,7 @@ class OrderingFilterTests(TestCase):
|
||||||
ordering = ('title',)
|
ordering = ('title',)
|
||||||
|
|
||||||
view = OrderingListView.as_view()
|
view = OrderingListView.as_view()
|
||||||
request = factory.get('?order=foobar')
|
request = factory.get('?ordering=foobar')
|
||||||
response = view(request)
|
response = view(request)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
response.data,
|
response.data,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user