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 117e376

Browse files
committed
Use extra requires to separate optional features
Fixes #674 Currently only django-filter and django-polymorphic use the extra_requires definition.
1 parent 70bbb0e commit 117e376

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

‎README.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ From PyPI
101101
::
102102

103103
$ pip install djangorestframework-jsonapi
104+
$ # for optional package integrations
105+
$ pip install djangorestframework-jsonapi['django-filter']
106+
$ pip install djangorestframework-jsonapi['django-polymorphic']
104107

105108

106109
From Source

‎docs/getting-started.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ like the following:
6060
From PyPI
6161

6262
pip install djangorestframework-jsonapi
63+
# for optional package integrations
64+
pip install djangorestframework-jsonapi['django-filter']
65+
pip install djangorestframework-jsonapi['django-polymorphic']
6366

6467
From Source
6568

‎docs/usage.md‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
The DJA package implements a custom renderer, parser, exception handler, query filter backends, and
55
pagination. 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
88
Mixin classes in `serializers.py`.
99
The easiest way to make use of those features is to import ModelSerializer variants
1010
from `rest_framework_json_api` instead of the usual `rest_framework`
@@ -108,7 +108,8 @@ class MyLimitPagination(JsonApiLimitOffsetPagination):
108108
Following are descriptions of JSON:API-specific filter backends and documentation on suggested usage
109109
for 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
114115
is used. This can help the client identify misspelled query parameters, for example.
@@ -131,7 +132,8 @@ class MyQPValidator(QueryValidationFilter):
131132
If you don't care if non-JSON:API query parameters are allowed (and potentially silently ignored),
132133
simply 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
136138
DRF'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:
155157
If 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)
160163
using 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-
188184
The filter returns a `400 Bad Request` error for invalid filter query parameters as in this example
189185
for `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

206206
To 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
211211
use [`DjangoFilterBackend`](#djangofilterbackend), make sure you set the same values for both classes.
212212

213213

214-
215214
#### Configuring Filter Backends
216215

217216
You can configure the filter backends either by setting the `REST_FRAMEWORK['DEFAULT_FILTER_BACKENDS']` as shown
218217
in the [example settings](#configuration) or individually add them as `.filter_backends` View attributes:
219-
218+
220219
```python
221220
from rest_framework_json_api import filters
222221
from rest_framework_json_api import django_filters
@@ -699,6 +698,10 @@ DJA tests its polymorphic support against [django-polymorphic](https://django-po
699698
The polymorphic feature should also work with other popular libraries like
700699
django-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

704707
A polymorphic endpoint can be set up if associated with a polymorphic serializer.

‎setup.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def get_package_data(package):
9090
'djangorestframework>=3.10',
9191
'django>=1.11',
9292
],
93+
extras_require={
94+
'django-polymorphic': ['django-polymorphic>=2.0'],
95+
'django-filter': ['django-filter>=2.0']
96+
},
9397
python_requires=">=3.5",
9498
zip_safe=False,
9599
)

0 commit comments

Comments
(0)

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