From 38e05e66c932fc2967cefbd88225bcdc2b0313a7 Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 4 Dec 2014 23:22:00 +0100 Subject: [PATCH 1/2] print() function works from Python 2.6 to 3.X --- docs/tutorial/1-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 52c75d2ca..b704996d1 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -210,7 +210,7 @@ One nice property that serializers have is that you can inspect all the fields i >>> from snippets.serializers import SnippetSerializer >>> serializer = SnippetSerializer() - >>> print repr(serializer) # In python 3 use `print(repr(serializer))` + >>> print(repr(serializer)) SnippetSerializer(): id = IntegerField(label='ID', read_only=True) title = CharField(allow_blank=True, max_length=100, required=False) From 9d078be59ca5067d098263b1892740b44f7c41ee Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 4 Dec 2014 23:34:55 +0100 Subject: [PATCH 2/2] Fix the tutorial against the v3.0 --- docs/tutorial/1-serialization.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index b704996d1..eb0a00c01 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -101,7 +101,7 @@ The first thing we need to get started on our Web API is to provide a way of ser class SnippetSerializer(serializers.Serializer): pk = serializers.IntegerField(read_only=True) - title = serializers.CharField(required=False, + title = serializers.CharField(required=False, allow_blank=True max_length=100) code = serializers.CharField(style={'type': 'textarea'}) linenos = serializers.BooleanField(required=False) @@ -181,7 +181,7 @@ Deserialization is similar. First we parse a stream into Python native datatype serializer = SnippetSerializer(data=data) serializer.is_valid() # True - serializer.object + serializer.save() # Notice how similar the API is to working with forms. The similarity should become even more apparent when we start writing views that use our serializer. @@ -301,7 +301,7 @@ We'll also need a view which corresponds to an individual snippet, and can be us Finally we need to wire these views up. Create the `snippets/urls.py` file: - from django.conf.urls import patterns, url + from django.conf.urls import url from snippets import views urlpatterns = [