Set to false if this field is not required to be present during deserialization.</p>
Set to false if this field is not required to be present during deserialization.</p>
<p>Defaults to <code>True</code>.</p>
<p>Defaults to <code>True</code>.</p>
<h3id="default"><code>default</code></h3>
<h3id="default"><code>default</code></h3>
<p>If set, this gives the default value that will be used for the field if none is supplied. If not set the default behavior is to not populate the attribute at all. </p>
<p>If set, this gives the default value that will be used for the field if no input value is supplied. If not set the default behavior is to not populate the attribute at all. </p>
<p>May be set to a function or other callable, in which case the value will be evaluated each time it is used.</p>
<p>May be set to a function or other callable, in which case the value will be evaluated each time it is used.</p>
<h3id="validators"><code>validators</code></h3>
<h3id="validators"><code>validators</code></h3>
<p>A list of Django validators that should be used to validate deserialized values.</p>
<p>A list of Django validators that should be used to validate deserialized values.</p>
...
@@ -407,7 +408,7 @@ or <code>django.db.models.fields.TextField</code>.</p>
...
@@ -407,7 +408,7 @@ or <code>django.db.models.fields.TextField</code>.</p>
<h2id="imagefield">ImageField</h2>
<h2id="imagefield">ImageField</h2>
<p>An image representation.</p>
<p>An image representation.</p>
<p>Corresponds to <code>django.forms.fields.ImageField</code>.</p>
<p>Corresponds to <code>django.forms.fields.ImageField</code>.</p>
<p>Requires the <code>PIL</code> package.</p>
<p>Requires either the <code>Pillow</code> package or <code>PIL</code> package. The <code>Pillow</code> package is recommended, as <code>PIL</code> is no longer actively maintained.</p>
<p>Signature and validation is the same as with <code>FileField</code>.</p>
<p>Signature and validation is the same as with <code>FileField</code>.</p>
<hr/>
<hr/>
<p><strong>Note:</strong><code>FileFields</code> and <code>ImageFields</code> are only suitable for use with MultiPartParser, since e.g. json doesn't support file uploads.
<p><strong>Note:</strong><code>FileFields</code> and <code>ImageFields</code> are only suitable for use with MultiPartParser, since e.g. json doesn't support file uploads.
@@ -346,11 +347,13 @@ class UserList(generics.ListCreateAPIView):
...
@@ -346,11 +347,13 @@ class UserList(generics.ListCreateAPIView):
return 20
return 20
return 100
return 100
</code></pre>
</code></pre>
<p><strong>Save hooks</strong>:</p>
<p><strong>Save / deletion hooks</strong>:</p>
<p>The following methods are provided as placeholder interfaces. They contain empty implementations and are not called directly by <code>GenericAPIView</code>, but they are overridden and used by some of the mixin classes.</p>
<p>The following methods are provided as placeholder interfaces. They contain empty implementations and are not called directly by <code>GenericAPIView</code>, but they are overridden and used by some of the mixin classes.</p>
<ul>
<ul>
<li><code>pre_save(self, obj)</code> - A hook that is called before saving an object.</li>
<li><code>pre_save(self, obj)</code> - A hook that is called before saving an object.</li>
<li><code>post_save(self, obj, created=False)</code> - A hook that is called after saving an object.</li>
<li><code>post_save(self, obj, created=False)</code> - A hook that is called after saving an object.</li>
<li><code>pre_delete(self, obj)</code> - A hook that is called before deleting an object.</li>
<li><code>post_delete(self, obj)</code> - A hook that is called after deleting an object.</li>
</ul>
</ul>
<p>The <code>pre_save</code> method in particular is a useful hook for setting attributes that are implicit in the request, but are not part of the request data. For instance, you might set an attribute on the object based on the request user, or based on a URL keyword argument.</p>
<p>The <code>pre_save</code> method in particular is a useful hook for setting attributes that are implicit in the request, but are not part of the request data. For instance, you might set an attribute on the object based on the request user, or based on a URL keyword argument.</p>
@@ -347,7 +348,7 @@ class UserViewSet(viewsets.ModelViewSet):
...
@@ -347,7 +348,7 @@ class UserViewSet(viewsets.ModelViewSet):
<p>The <code>ModelViewSet</code> class inherits from <code>GenericAPIView</code> and includes implementations for various actions, by mixing in the behavior of the various mixin classes.</p>
<p>The <code>ModelViewSet</code> class inherits from <code>GenericAPIView</code> and includes implementations for various actions, by mixing in the behavior of the various mixin classes.</p>
<p>The actions provided by the <code>ModelViewSet</code> class are <code>.list()</code>, <code>.retrieve()</code>, <code>.create()</code>, <code>.update()</code>, and <code>.destroy()</code>.</p>
<p>The actions provided by the <code>ModelViewSet</code> class are <code>.list()</code>, <code>.retrieve()</code>, <code>.create()</code>, <code>.update()</code>, and <code>.destroy()</code>.</p>
<h4id="example_1">Example</h4>
<h4id="example_1">Example</h4>
<p>Because <code>ModelViewSet</code> extends <code>GenericAPIView</code>, you'll normally need to provide at least the <code>queryset</code> and <code>serializer_class</code> attributes. For example:</p>
<p>Because <code>ModelViewSet</code> extends <code>GenericAPIView</code>, you'll normally need to provide at least the <code>queryset</code> and <code>serializer_class</code> attributes, or the <code>model</code> attribute shortcut. For example:</p>