diff options
| author | Tom Christie | 2014-12-17 16:32:42 +0000 | 
|---|---|---|
| committer | Tom Christie | 2014-12-17 16:32:42 +0000 | 
| commit | a0a601301ff0a42d1e0905d29194e638690f32bb (patch) | |
| tree | 1e71a36ef3ffe78ea68385dbc3c246102a5aa490 /api-guide | |
| parent | 760da25c6018eff02b3aab33dc6fea7c93881d9f (diff) | |
| download | django-rest-framework-a0a601301ff0a42d1e0905d29194e638690f32bb.tar.bz2 | |
Update documentation
Diffstat (limited to 'api-guide')
| -rw-r--r-- | api-guide/serializers/index.html | 10 | 
1 files changed, 6 insertions, 4 deletions
| diff --git a/api-guide/serializers/index.html b/api-guide/serializers/index.html index 54888896..4c03b25f 100644 --- a/api-guide/serializers/index.html +++ b/api-guide/serializers/index.html @@ -562,11 +562,13 @@ will take some serious design work.</p>  <p>The serializers in REST framework work very similarly to Django's <code>Form</code> and <code>ModelForm</code> classes. We provide a <code>Serializer</code> class which gives you a powerful, generic way to control the output of your responses, as well as a <code>ModelSerializer</code> class which provides a useful shortcut for creating serializers that deal with model instances and querysets.</p>  <h2 id="declaring-serializers">Declaring Serializers</h2>  <p>Let's start by creating a simple object we can use for example purposes:</p> -<pre><code>class Comment(object): +<pre><code>from datetime import datetime + +class Comment(object):      def __init__(self, email, content, created=None):          self.email = email          self.content = content -        self.created = created or datetime.datetime.now() +        self.created = created or datetime.now()  comment = Comment(email='leila@example.com', content='foo bar')  </code></pre> @@ -594,10 +596,10 @@ json  </code></pre>  <h2 id="deserializing-objects">Deserializing objects</h2>  <p>Deserialization is similar. First we parse a stream into Python native datatypes...</p> -<pre><code>from StringIO import StringIO +<pre><code>from django.utils.six import BytesIO  from rest_framework.parsers import JSONParser -stream = StringIO(json) +stream = BytesIO(json)  data = JSONParser().parse(stream)  </code></pre>  <p>...then we restore those native datatypes into a dictionary of validated data.</p> | 
