Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0d7afcc

Browse files
committed
rename backends to filters
1 parent e6290af commit 0d7afcc

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

‎docs/usage.md‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ REST_FRAMEWORK = {
3333
),
3434
'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
3535
'DEFAULT_FILTER_BACKENDS': (
36-
'rest_framework_json_api.backends.JSONAPIOrderingFilter',
36+
'rest_framework_json_api.filters.JSONAPIOrderingFilter',
3737
),
3838
'TEST_REQUEST_RENDERER_CLASSES': (
3939
'rest_framework_json_api.renderers.JSONRenderer',
@@ -98,7 +98,7 @@ _This is the first of several anticipated JSON:API-specific filter backends._
9898
`JSONAPIOrderingFilter` implements the [JSON:API `sort`](http://jsonapi.org/format/#fetching-sorting) and uses
9999
DRF's [ordering filter](http://django-rest-framework.readthedocs.io/en/latest/api-guide/filtering/#orderingfilter).
100100

101-
Per the JSON:API, "If the server does not support sorting as specified in the query parameter `sort`,
101+
Per the JSON:API specification, "If the server does not support sorting as specified in the query parameter `sort`,
102102
it **MUST** return `400 Bad Request`." For example, for `?sort=`abc,foo,def` where `foo` is a valid
103103
field name and the other two are not valid:
104104
```json
@@ -118,6 +118,20 @@ field name and the other two are not valid:
118118
If you want to silently ignore bad sort fields, just use `rest_framework.filters.OrderingFilter` and set
119119
`ordering_param` to `sort`.
120120

121+
#### Configuring Filter Backends
122+
123+
You can configure the filter backends either by setting the `REST_FRAMEWORK['DEFAULT_FILTER_BACKENDS']` as shown
124+
in the [preceding](#configuration) example or individually add them as `.filter_backends` View attributes:
125+
126+
```python
127+
from rest_framework_json_api import filters
128+
129+
class MyViewset(ModelViewSet):
130+
queryset = MyModel.objects.all()
131+
serializer_class = MyModelSerializer
132+
filter_backends = (filters.JSONAPIOrderingFilter,)
133+
```
134+
121135

122136
### Performance Testing
123137

‎example/settings/dev.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@
8989
),
9090
'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
9191
'DEFAULT_FILTER_BACKENDS': (
92-
'rest_framework_json_api.backends.JSONAPIOrderingFilter',
92+
'rest_framework_json_api.filters.JSONAPIOrderingFilter',
9393
),
94-
'ORDERING_PARAM': 'sort',
9594
'TEST_REQUEST_RENDERER_CLASSES': (
9695
'rest_framework_json_api.renderers.JSONRenderer',
9796
),
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /