You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -102,7 +104,8 @@ class MyLimitPagination(JsonApiLimitOffsetPagination):
102
104
103
105
### Filter Backends
104
106
105
-
_There are several anticipated JSON:API-specific filter backends in development. The first two are described below._
107
+
Following are descriptions for two JSON:API-specific filter backends and documentation on suggested usage
108
+
for a standard DRF keyword-search filter backend that makes it consistent with JSON:API.
106
109
107
110
#### `OrderingFilter`
108
111
`OrderingFilter` implements the [JSON:API`sort`](http://jsonapi.org/format/#fetching-sorting) and uses
@@ -151,12 +154,12 @@ Filters can be:
151
154
- A related resource path can be used:
152
155
`?filter[inventory.item.partNum]=123456` (where `inventory.item` is the relationship path)
153
156
154
-
If you are also using [`rest_framework.filters.SearchFilter`](https://django-rest-framework.readthedocs.io/en/latest/api-guide/filtering/#searchfilter)
155
-
(which performs single parameter searchs across multiple fields) you'll want to customize the name of the query
157
+
If you are also using [`SearchFilter`](#searchfilter)
158
+
(which performs single parameter searches across multiple fields) you'll want to customize the name of the query
156
159
parameter for searching to make sure it doesn't conflict with a field name defined in the filterset.
157
160
The recommended value is: `search_param="filter[search]"` but just make sure it's
158
161
`filter[_something_]` to comply with the JSON:API spec requirement to use the filter
159
-
keyword. The default is "search" unless overriden.
162
+
keyword. The default is `REST_FRAMEWORK['SEARCH_PARAM']` unless overriden.
160
163
161
164
The filter returns a `400 Bad Request` error for invalid filter query parameters as in this example
162
165
for `GET http://127.0.0.1:8000/nopage-entries?filter[bad]=1`:
@@ -173,6 +176,15 @@ for `GET http://127.0.0.1:8000/nopage-entries?filter[bad]=1`:
173
176
]
174
177
}
175
178
```
179
+
#### `SearchFilter`
180
+
181
+
To comply with JSON:API query parameter naming standards, DRF's
182
+
[SearchFilter](https://django-rest-framework.readthedocs.io/en/latest/api-guide/filtering/#searchfilter) should
183
+
be configured to use a `filter[_something_]` query parameter. This can be done by default by adding the
184
+
SearchFilter to `REST_FRAMEWORK['DEFAULT_FILTER_BACKENDS']` and setting `REST_FRAMEWORK['SEARCH_PARAM']` or
185
+
adding the `.search_param` attribute to a custom class derived from `SearchFilter`. If you do this and also
186
+
use [`DjangoFilterBackend`](#djangofilterbackend), make sure you set the same values for both classes.
187
+
176
188
177
189
#### Configuring Filter Backends
178
190
@@ -182,11 +194,19 @@ in the [example settings](#configuration) or individually add them as `.filter_b
182
194
```python
183
195
from rest_framework_json_api import filters
184
196
from rest_framework_json_api import django_filters
0 commit comments