From a0a601301ff0a42d1e0905d29194e638690f32bb Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 17 Dec 2014 16:32:42 +0000 Subject: [PATCH] Update documentation --- api-guide/serializers/index.html | 10 ++++++---- tutorial/1-serialization/index.html | 4 +--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api-guide/serializers/index.html b/api-guide/serializers/index.html index 548888968..4c03b25fc 100644 --- a/api-guide/serializers/index.html +++ b/api-guide/serializers/index.html @@ -562,11 +562,13 @@ will take some serious design work.

The serializers in REST framework work very similarly to Django's Form and ModelForm classes. We provide a Serializer class which gives you a powerful, generic way to control the output of your responses, as well as a ModelSerializer class which provides a useful shortcut for creating serializers that deal with model instances and querysets.

Declaring Serializers

Let's start by creating a simple object we can use for example purposes:

-
class Comment(object):
+
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')
 
@@ -594,10 +596,10 @@ json

Deserializing objects

Deserialization is similar. First we parse a stream into Python native datatypes...

-
from StringIO import StringIO
+
from django.utils.six import BytesIO
 from rest_framework.parsers import JSONParser
 
-stream = StringIO(json)
+stream = BytesIO(json)
 data = JSONParser().parse(stream)
 

...then we restore those native datatypes into a dictionary of validated data.

diff --git a/tutorial/1-serialization/index.html b/tutorial/1-serialization/index.html index 5682989c4..0561fab1a 100644 --- a/tutorial/1-serialization/index.html +++ b/tutorial/1-serialization/index.html @@ -533,9 +533,7 @@ content # '{"pk": 2, "title": "", "code": "print \\"hello, world\\"\\n", "linenos": false, "language": "python", "style": "friendly"}'

Deserialization is similar. First we parse a stream into Python native datatypes...

-
# This import will use either `StringIO.StringIO` or `io.BytesIO`
-# as appropriate, depending on if we're running Python 2 or Python 3.
-from django.utils.six import BytesIO
+
from django.utils.six import BytesIO
 
 stream = BytesIO(content)
 data = JSONParser().parse(stream)