<p>The value <code>source='*'</code> has a special meaning, and is used to indicate that the entire object should be passed through to the field. This can be useful for creating nested representations. (See the implementation of the <code>PaginationSerializer</code> class for an example.)</p>
<p>The value <code>source='*'</code> has a special meaning, and is used to indicate that the entire object should be passed through to the field. This can be useful for creating nested representations. (See the implementation of the <code>PaginationSerializer</code> class for an example.)</p>
<p>Defaults to the name of the field.</p>
<p>Defaults to the name of the field.</p>
<h3id="read_only"><code>read_only</code></h3>
<h3id="read_only"><code>read_only</code></h3>
<p>Set this to <code>True</code> to ensure that the field is used when serializing a representation, but is not used when updating an instance during deserialization.</p>
<p>Set this to <code>True</code> to ensure that the field is used when serializing a representation, but is not used when creating or updating an instance during deserialization.</p>
<p>Defaults to <code>False</code></p>
<h3id="write_only"><code>write_only</code></h3>
<p>Set this to <code>True</code> to ensure that the field may be used when updating or creating an instance, but is not included when serializing the representation.</p>
<p>Defaults to <code>False</code></p>
<p>Defaults to <code>False</code></p>
<h3id="required"><code>required</code></h3>
<h3id="required"><code>required</code></h3>
<p>Normally an error will be raised if a field is not supplied during deserialization.
<p>Normally an error will be raised if a field is not supplied during deserialization.
...
@@ -313,10 +316,10 @@ or <code>django.db.models.fields.TextField</code>.</p>
...
@@ -313,10 +316,10 @@ or <code>django.db.models.fields.TextField</code>.</p>
<p>By default, serializers must be passed values for all required fields or they will throw validation errors. You can use the <code>partial</code> argument in order to allow partial updates.</p>
<p>By default, serializers must be passed values for all required fields or they will throw validation errors. You can use the <code>partial</code> argument in order to allow partial updates.</p>
<preclass="prettyprint lang-py"><code>serializer = CommentSerializer(comment, data={'content': u'foo bar'}, partial=True) # Update `instance` with partial data
<preclass="prettyprint lang-py"><code>serializer = CommentSerializer(comment, data={'content': u'foo bar'}, partial=True) # Update `comment` with partial data
</code></pre>
</code></pre>
<h2id="validation">Validation</h2>
<h2id="validation">Validation</h2>
<p>When deserializing data, you always need to call <code>is_valid()</code> before attempting to access the deserialized object. If any validation errors occur, the <code>.errors</code> property will contain a dictionary representing the resulting error messages. For example:</p>
<p>When deserializing data, you always need to call <code>is_valid()</code> before attempting to access the deserialized object. If any validation errors occur, the <code>.errors</code> property will contain a dictionary representing the resulting error messages. For example:</p>
...
@@ -368,7 +369,7 @@ class CommentSerializer(serializers.Serializer):
...
@@ -368,7 +369,7 @@ class CommentSerializer(serializers.Serializer):
created = serializers.DateTimeField()
created = serializers.DateTimeField()
</code></pre>
</code></pre>
<p>Validation of nested objects will work the same as before. Errors with nested objects will be nested under the field name of the nested object.</p>
<p>Validation of nested objects will work the same as before. Errors with nested objects will be nested under the field name of the nested object.</p>
@@ -494,6 +495,23 @@ The <code>ModelSerializer</code> class lets you automatically create a Serialize
...
@@ -494,6 +495,23 @@ The <code>ModelSerializer</code> class lets you automatically create a Serialize
read_only_fields = ('account_name',)
read_only_fields = ('account_name',)
</code></pre>
</code></pre>
<p>Model fields which have <code>editable=False</code> set, and <code>AutoField</code> fields will be set to read-only by default, and do not need to be added to the <code>read_only_fields</code> option. </p>
<p>Model fields which have <code>editable=False</code> set, and <code>AutoField</code> fields will be set to read-only by default, and do not need to be added to the <code>read_only_fields</code> option. </p>
<h2id="specifying-which-fields-should-be-write-only">Specifying which fields should be write-only</h2>
<p>You may wish to specify multiple fields as write-only. Instead of adding each field explicitly with the <code>write_only=True</code> attribute, you may use the <code>write_only_fields</code> Meta option, like so:</p>
<p>You can add extra fields to a <code>ModelSerializer</code> or override the default fields by declaring fields on the class, just as you would for a <code>Serializer</code> class.</p>
<p>You can add extra fields to a <code>ModelSerializer</code> or override the default fields by declaring fields on the class, just as you would for a <code>Serializer</code> class.</p>
<li>Added <code>write_only</code> serializer field argument.</li>
<li>Added <code>write_only_fields</code> option to <code>ModelSerializer</code> classes.</li>
<li>JSON renderer now deals with objects that implement a dict-like interface.</li>
<li>JSON renderer now deals with objects that implement a dict-like interface.</li>
<li>Fix compatiblity with newer versions of <code>django-oauth-plus</code>.</li>
<li>Fix compatiblity with newer versions of <code>django-oauth-plus</code>.</li>
<li>Bugfix: Refine behavior that calls model manager <code>all()</code> across nested serializer relationships, preventing erronous behavior with some non-ORM objects, and preventing unneccessary queryset re-evaluations.</li>
<li>Bugfix: Refine behavior that calls model manager <code>all()</code> across nested serializer relationships, preventing erronous behavior with some non-ORM objects, and preventing unneccessary queryset re-evaluations.</li>