mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-25 11:33:43 +03:00
Latest release notes
This commit is contained in:
parent
4798df52df
commit
657d1de032
|
@ -560,6 +560,35 @@ The following usage will *now raise an error*:
|
||||||
|
|
||||||
email = serializers.EmailField(source='email')
|
email = serializers.EmailField(source='email')
|
||||||
|
|
||||||
|
#### The `UniqueValidator` and `UniqueTogetherValidator` classes.
|
||||||
|
|
||||||
|
REST framework now provides two new validators that allow you to ensure field uniqueness, while still using a completely explicit `Serializer` class instead of using `ModelSerializer`.
|
||||||
|
|
||||||
|
The `UniqueValidator` should be applied to a serializer field, and takes a single `queryset` argument.
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
from rest_framework.validators import UniqueValidator
|
||||||
|
|
||||||
|
class OrganizationSerializer(serializers.Serializer):
|
||||||
|
url = serializers.HyperlinkedIdentityField(view_name='organisation_detail')
|
||||||
|
created = serializers.DateTimeField(read_only=True)
|
||||||
|
name = serializers.CharField(
|
||||||
|
max_length=100,
|
||||||
|
validators=UniqueValidator(queryset=Organisation.objects.all())
|
||||||
|
)
|
||||||
|
|
||||||
|
The `UniqueTogetherValidator` should be applied to a serializer, and takes a `queryset` argument and a `fields` argument which should be a list or tuple of field names.
|
||||||
|
|
||||||
|
class RaceResultSerializer(serializers.Serializer):
|
||||||
|
category = serializers.ChoiceField(['5k', '10k'])
|
||||||
|
position = serializers.IntegerField()
|
||||||
|
name = serializers.CharField(max_length=100)
|
||||||
|
|
||||||
|
default_validators = [UniqueTogetherValidator(
|
||||||
|
queryset=RaceResult.objects.all(),
|
||||||
|
fields=('category', 'position')
|
||||||
|
)]
|
||||||
|
|
||||||
## Generic views
|
## Generic views
|
||||||
|
|
||||||
#### Simplification of view logic.
|
#### Simplification of view logic.
|
||||||
|
@ -633,6 +662,16 @@ The `COMPACT_JSON` setting has been added, and can be used to revert this behavi
|
||||||
'COMPACT_JSON': False
|
'COMPACT_JSON': False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#### File fields as URLs
|
||||||
|
|
||||||
|
The `FileField` and `ImageField` classes are now represented as URLs by default. You should ensure you set Django's standard `MEDIA_URL` setting appropriately.
|
||||||
|
|
||||||
|
You can revert this behavior, and display filenames as the representation, using the `UPLOADED_FILES_USE_URL` settings key:
|
||||||
|
|
||||||
|
REST_FRAMEWORK = {
|
||||||
|
'UPLOADED_FILES_USE_URL': False
|
||||||
|
}
|
||||||
|
|
||||||
#### Throttle headers using `Retry-After`.
|
#### Throttle headers using `Retry-After`.
|
||||||
|
|
||||||
The custom `X-Throttle-Wait-Second` header has now been dropped in favor of the standard `Retry-After` header. You can revert this behavior if needed by writing a custom exception handler for your application.
|
The custom `X-Throttle-Wait-Second` header has now been dropped in favor of the standard `Retry-After` header. You can revert this behavior if needed by writing a custom exception handler for your application.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user