44The DJA package implements a custom renderer, parser, exception handler, query filter backends, and
55pagination. To get started enable the pieces in ` settings.py ` that you want to use.
66
7- Many features of the [ JSON: API ] ( http://jsonapi.org/format ) format standard have been implemented using
7+ Many features of the [ JSON: API ] ( http://jsonapi.org/format ) format standard have been implemented using
88Mixin classes in ` serializers.py ` .
99The easiest way to make use of those features is to import ModelSerializer variants
1010from ` rest_framework_json_api ` instead of the usual ` rest_framework `
@@ -108,7 +108,8 @@ class MyLimitPagination(JsonApiLimitOffsetPagination):
108108Following are descriptions of JSON: API-specific filter backends and documentation on suggested usage
109109for a standard DRF keyword-search filter backend that makes it consistent with JSON: API .
110110
111- #### ` QueryParameterValidationFilter `
111+ #### QueryParameterValidationFilter
112+
112113` QueryParameterValidationFilter ` validates query parameters to be one of the defined JSON: API query parameters
113114(sort, include, filter, fields, page) and returns a ` 400 Bad Request ` if a non-matching query parameter
114115is used. This can help the client identify misspelled query parameters, for example.
@@ -131,7 +132,8 @@ class MyQPValidator(QueryValidationFilter):
131132If you don't care if non-JSON: API query parameters are allowed (and potentially silently ignored),
132133simply don't use this filter backend.
133134
134- #### ` OrderingFilter `
135+ #### OrderingFilter
136+
135137` OrderingFilter ` implements the [ JSON: API ` sort ` ] ( http://jsonapi.org/format/#fetching-sorting ) and uses
136138DRF's [ ordering filter] ( http://django-rest-framework.readthedocs.io/en/latest/api-guide/filtering/#orderingfilter ) .
137139
@@ -155,7 +157,8 @@ field name and the other two are not valid:
155157If you want to silently ignore bad sort fields, just use ` rest_framework.filters.OrderingFilter ` and set
156158` ordering_param ` to ` sort ` .
157159
158- #### ` DjangoFilterBackend `
160+ #### DjangoFilterBackend
161+
159162` DjangoFilterBackend ` implements a Django ORM-style [ JSON: API ` filter ` ] ( http://jsonapi.org/format/#fetching-filtering )
160163using the [ django-filter] ( https://django-filter.readthedocs.io/ ) package.
161164
@@ -178,13 +181,6 @@ Filters can be:
178181- A related resource path can be used:
179182 ` ?filter[inventory.item.partNum]=123456 ` (where ` inventory.item ` is the relationship path)
180183
181- If you are also using [ ` SearchFilter ` ] ( #searchfilter )
182- (which performs single parameter searches across multiple fields) you'll want to customize the name of the query
183- parameter for searching to make sure it doesn't conflict with a field name defined in the filterset.
184- The recommended value is: ` search_param="filter[search]" ` but just make sure it's
185- ` filter[_something_] ` to comply with the JSON: API spec requirement to use the filter
186- keyword. The default is ` REST_FRAMEWORK['SEARCH_PARAM'] ` unless overriden.
187-
188184The filter returns a ` 400 Bad Request ` error for invalid filter query parameters as in this example
189185for ` GET http://127.0.0.1:8000/nopage-entries?filter[bad]=1 ` :
190186``` json
@@ -201,7 +197,11 @@ for `GET http://127.0.0.1:8000/nopage-entries?filter[bad]=1`:
201197}
202198```
203199
204- #### ` SearchFilter `
200+ As this feature depends on ` django-filter ` you need to run
201+
202+ pip install djangorestframework-jsonapi['django-filter']
203+
204+ #### SearchFilter
205205
206206To comply with JSON: API query parameter naming standards, DRF's
207207[ SearchFilter] ( https://django-rest-framework.readthedocs.io/en/latest/api-guide/filtering/#searchfilter ) should
@@ -211,12 +211,11 @@ adding the `.search_param` attribute to a custom class derived from `SearchFilte
211211use [ ` DjangoFilterBackend ` ] ( #djangofilterbackend ) , make sure you set the same values for both classes.
212212
213213
214-
215214#### Configuring Filter Backends
216215
217216You can configure the filter backends either by setting the ` REST_FRAMEWORK['DEFAULT_FILTER_BACKENDS'] ` as shown
218217in the [ example settings] ( #configuration ) or individually add them as ` .filter_backends ` View attributes:
219-
218+
220219 ``` python
221220from rest_framework_json_api import filters
222221from rest_framework_json_api import django_filters
@@ -699,6 +698,10 @@ DJA tests its polymorphic support against [django-polymorphic](https://django-po
699698The polymorphic feature should also work with other popular libraries like
700699django-polymodels or django-typed-models.
701700
701+ As this feature depends on ` django-polymorphic ` you need to run
702+
703+ pip install djangorestframework-jsonapi['django-polymorphic']
704+
702705#### Writing polymorphic resources
703706
704707A polymorphic endpoint can be set up if associated with a polymorphic serializer.
0 commit comments