diff options
| author | Tom Christie | 2014-01-14 11:25:44 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-01-14 11:25:44 +0000 | 
| commit | 85d74fc86a934309359a437dd487193013055977 (patch) | |
| tree | 6c7ab1a100f61c7102d728ac6cd7dd788ed739fd /docs | |
| parent | bc6c5df109a35bf76be662a47d9c88a2a3b82351 (diff) | |
| download | django-rest-framework-85d74fc86a934309359a437dd487193013055977.tar.bz2 | |
Added write_only and write_only_fields.  Refs #1306
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/api-guide/fields.md | 8 | ||||
| -rw-r--r-- | docs/api-guide/serializers.md | 19 | ||||
| -rw-r--r-- | docs/topics/release-notes.md | 6 | 
3 files changed, 31 insertions, 2 deletions
| diff --git a/docs/api-guide/fields.md b/docs/api-guide/fields.md index 91866664..c136509b 100644 --- a/docs/api-guide/fields.md +++ b/docs/api-guide/fields.md @@ -28,7 +28,13 @@ Defaults to the name of the field.  ### `read_only` -Set this to `True` to ensure that the field is used when serializing a representation, but is not used when updating an instance during deserialization. +Set this to `True` to ensure that the field is used when serializing a representation, but is not used when creating or updating an instance during deserialization. + +Defaults to `False` + +### `write_only` + +Set this to `True` to ensure that the field may be used when updating or creating an instance, but is not included when serializing the representation.  Defaults to `False` diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 04439092..b05acfd5 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -373,6 +373,25 @@ You may wish to specify multiple fields as read-only.  Instead of adding each fi  Model fields which have `editable=False` set, and `AutoField` fields will be set to read-only by default, and do not need to be added to the `read_only_fields` option.  +## Specifying which fields should be write-only  + +You may wish to specify multiple fields as write-only.  Instead of adding each field explicitly with the `write_only=True` attribute, you may use the `write_only_fields` Meta option, like so: + +    class CreateUserSerializer(serializers.ModelSerializer): +        class Meta: +            model = User +            fields = ('email', 'username', 'password') +            write_only_fields = ('password',)  # Note: Password field is write-only + +    def restore_object(self, attrs, instance=None): +        """ +        Instantiate a new User instance. +        """ +        assert instance is None, 'Cannot update users with CreateUserSerializer'                                 +        user = User(email=attrs['email'], username=attrs['username']) +        user.set_password(attrs['password']) +        return user +   ## Specifying fields explicitly   You can add extra fields to a `ModelSerializer` or override the default fields by declaring fields on the class, just as you would for a `Serializer` class. diff --git a/docs/topics/release-notes.md b/docs/topics/release-notes.md index ca966d20..cd87c7b2 100644 --- a/docs/topics/release-notes.md +++ b/docs/topics/release-notes.md @@ -40,8 +40,12 @@ You can determine your currently installed version using `pip freeze`:  ## 2.3.x series -### Master +### 2.3.11 +**Date**: 14th January 2014 + +* Added `write_only` serializer field argument. +* Added `write_only_fields` option to `ModelSerializer` classes.  * JSON renderer now deals with objects that implement a dict-like interface.  * Fix compatiblity with newer versions of `django-oauth-plus`.  * Bugfix: Refine behavior that calls model manager `all()` across nested serializer relationships, preventing erronous behavior with some non-ORM objects, and preventing unneccessary queryset re-evaluations. | 
