diff options
| author | Tom Christie | 2014-09-29 14:12:09 +0100 | 
|---|---|---|
| committer | Tom Christie | 2014-09-29 14:12:09 +0100 | 
| commit | 657d1de032bfa392609d53751e89366b972cd678 (patch) | |
| tree | ee53ad01298eb0828438152e63c754965ffbf530 | |
| parent | 4798df52df5d59cc570043e3eb7e26f7ce57b54f (diff) | |
| download | django-rest-framework-657d1de032bfa392609d53751e89366b972cd678.tar.bz2 | |
Latest release notes
| -rw-r--r-- | docs/topics/3.0-announcement.md | 39 | 
1 files changed, 39 insertions, 0 deletions
| diff --git a/docs/topics/3.0-announcement.md b/docs/topics/3.0-announcement.md index 92062552..584c4979 100644 --- a/docs/topics/3.0-announcement.md +++ b/docs/topics/3.0-announcement.md @@ -560,6 +560,35 @@ The following usage will *now raise an error*:      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  #### 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      } +#### 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`.  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. | 
