| 1 |
<style> |
| 2 |
.promo li a { |
| 3 |
float: left; |
| 4 |
width: 130px; |
| 5 |
height: 20px; |
| 6 |
text-align: center; |
| 7 |
margin: 10px 30px; |
| 8 |
padding: 150px 0 0 0; |
| 9 |
background-position: 0 50%; |
| 10 |
background-size: 130px auto; |
| 11 |
background-repeat: no-repeat; |
| 12 |
font-size: 120%; |
| 13 |
color: black; |
| 14 |
} |
| 15 |
.promo li { |
| 16 |
list-style: none; |
| 17 |
} |
| 18 |
</style> |
| 19 |
|
| 20 |
# Django REST framework 3.11 |
| 21 |
|
| 22 |
The 3.11 release adds support for Django 3.0. |
| 23 |
|
| 24 |
* Our supported Python versions are now: 3.5, 3.6, 3.7, and 3.8. |
| 25 |
* Our supported Django versions are now: 1.11, 2.0, 2.1, 2.2, and 3.0. |
| 26 |
|
| 27 |
This release will be the last to support Python 3.5 or Django 1.11. |
| 28 |
|
| 29 |
## OpenAPI Schema Generation Improvements |
| 30 |
|
| 31 |
The OpenAPI schema generation continues to mature. Some highlights in 3.11 |
| 32 |
include: |
| 33 |
|
| 34 |
* Automatic mapping of Django REST Framework renderers and parsers into OpenAPI |
| 35 |
request and response media-types. |
| 36 |
* Improved mapping JSON schema mapping types, for example in HStoreFields, and |
| 37 |
with large integer values. |
| 38 |
* Porting of the old CoreAPI parsing of docstrings to form OpenAPI operation |
| 39 |
descriptions. |
| 40 |
|
| 41 |
In this example view operation descriptions for the `get` and `post` methods will |
| 42 |
be extracted from the class docstring: |
| 43 |
|
| 44 |
```python |
| 45 |
class DocStringExampleListView(APIView): |
| 46 |
""" |
| 47 |
get: A description of my GET operation. |
| 48 |
post: A description of my POST operation. |
| 49 |
""" |
| 50 |
|
| 51 |
permission_classes = [permissions.IsAuthenticatedOrReadOnly] |
| 52 |
|
| 53 |
def get(self, request, *args, **kwargs): ... |
| 54 |
|
| 55 |
def post(self, request, *args, **kwargs): ... |
| 56 |
``` |
| 57 |
|
| 58 |
## Validator / Default Context |
| 59 |
|
| 60 |
In some circumstances a Validator class or a Default class may need to access the serializer field with which it is called, or the `.context` with which the serializer was instantiated. In particular: |
| 61 |
|
| 62 |
* Uniqueness validators need to be able to determine the name of the field to which they are applied, in order to run an appropriate database query. |
| 63 |
* The `CurrentUserDefault` needs to be able to determine the context with which the serializer was instantiated, in order to return the current user instance. |
| 64 |
|
| 65 |
Our previous approach to this was that implementations could include a `set_context` method, which would be called prior to validation. However this approach had issues with potential race conditions. We have now move this approach into a pending deprecation state. It will continue to function, but will be escalated to a deprecated state in 3.12, and removed entirely in 3.13. |
| 66 |
|
| 67 |
Instead, validators or defaults which require the serializer context, should include a `requires_context = True` attribute on the class. |
| 68 |
|
| 69 |
The `__call__` method should then include an additional `serializer_field` argument. |
| 70 |
|
| 71 |
Validator implementations will look like this: |
| 72 |
|
| 73 |
```python |
| 74 |
class CustomValidator: |
| 75 |
requires_context = True |
| 76 |
|
| 77 |
def __call__(self, value, serializer_field): ... |
| 78 |
``` |
| 79 |
|
| 80 |
Default implementations will look like this: |
| 81 |
|
| 82 |
```python |
| 83 |
class CustomDefault: |
| 84 |
requires_context = True |
| 85 |
|
| 86 |
def __call__(self, serializer_field): ... |
| 87 |
``` |
| 88 |
|
| 89 |
--- |
| 90 |
|
| 91 |
## Funding |
| 92 |
|
| 93 |
REST framework is a *collaboratively funded project*. If you use |
| 94 |
REST framework commercially we strongly encourage you to invest in its |
| 95 |
continued development by **[signing up for a paid plan][funding]**. |
| 96 |
|
| 97 |
*Every single sign-up helps us make REST framework long-term financially sustainable.* |
| 98 |
|
| 99 |
*Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Sentry](https://getsentry.com/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [ESG](https://software.esg-usa.com/), [Rollbar](https://rollbar.com/?utm_source=django&utm_medium=sponsorship&utm_campaign=freetrial), [Cadre](https://cadre.com), [Kloudless](https://hubs.ly/H0f30Lf0), [Lights On Software](https://lightsonsoftware.com), and [Retool](https://retool.com/?utm_source=djangorest&utm_medium=sponsorship).* |
| 100 |
|
| 101 |
[sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors |
| 102 |
[funding]: https://opencollective.com/django-rest-framework |