diff options
| author | Xavier Ordoquy | 2015-01-27 23:15:26 +0100 |
|---|---|---|
| committer | Xavier Ordoquy | 2015-01-27 23:15:26 +0100 |
| commit | 987880e13138a93d9cc0e44b7ed30297909f7b03 (patch) | |
| tree | 1925d91078eff41d05a8e9840c503b6117d41446 /tutorial | |
| parent | d8dbd8679080035de4e785a8e7b998fb01f4052b (diff) | |
| download | django-rest-framework-987880e13138a93d9cc0e44b7ed30297909f7b03.tar.bz2 | |
Update documentation
Diffstat (limited to 'tutorial')
| -rw-r--r-- | tutorial/1-serialization/index.html | 4 | ||||
| -rw-r--r-- | tutorial/3-class-based-views/index.html | 2 | ||||
| -rw-r--r-- | tutorial/4-authentication-and-permissions/index.html | 2 | ||||
| -rw-r--r-- | tutorial/5-relationships-and-hyperlinked-apis/index.html | 4 |
4 files changed, 7 insertions, 5 deletions
diff --git a/tutorial/1-serialization/index.html b/tutorial/1-serialization/index.html index 2363f355..6782a94c 100644 --- a/tutorial/1-serialization/index.html +++ b/tutorial/1-serialization/index.html @@ -565,13 +565,13 @@ serializer.data <p>Our <code>SnippetSerializer</code> class is replicating a lot of information that's also contained in the <code>Snippet</code> model. It would be nice if we could keep our code a bit more concise.</p> <p>In the same way that Django provides both <code>Form</code> classes and <code>ModelForm</code> classes, REST framework includes both <code>Serializer</code> classes, and <code>ModelSerializer</code> classes.</p> <p>Let's look at refactoring our serializer using the <code>ModelSerializer</code> class. -Open the file <code>snippets/serializers.py</code> again, and edit the <code>SnippetSerializer</code> class.</p> +Open the file <code>snippets/serializers.py</code> again, and replace the <code>SnippetSerializer</code> class with the following.</p> <pre><code>class SnippetSerializer(serializers.ModelSerializer): class Meta: model = Snippet fields = ('id', 'title', 'code', 'linenos', 'language', 'style') </code></pre> -<p>One nice property that serializers have is that you can inspect all the fields in a serializer instance, by printing it's representation. Open the Django shell with <code>python manage.py shell</code>, then try the following:</p> +<p>One nice property that serializers have is that you can inspect all the fields in a serializer instance, by printing its representation. Open the Django shell with <code>python manage.py shell</code>, then try the following:</p> <pre><code>>>> from snippets.serializers import SnippetSerializer >>> serializer = SnippetSerializer() >>> print(repr(serializer)) diff --git a/tutorial/3-class-based-views/index.html b/tutorial/3-class-based-views/index.html index 8d3886c9..03263869 100644 --- a/tutorial/3-class-based-views/index.html +++ b/tutorial/3-class-based-views/index.html @@ -441,7 +441,7 @@ class SnippetList(APIView): </code></pre> <p>That's looking good. Again, it's still pretty similar to the function based view right now.</p> <p>We'll also need to refactor our <code>urls.py</code> slightly now we're using class based views.</p> -<pre><code>from django.conf.urls import patterns, url +<pre><code>from django.conf.urls import url from rest_framework.urlpatterns import format_suffix_patterns from snippets import views diff --git a/tutorial/4-authentication-and-permissions/index.html b/tutorial/4-authentication-and-permissions/index.html index c05e6cee..e4e5fccc 100644 --- a/tutorial/4-authentication-and-permissions/index.html +++ b/tutorial/4-authentication-and-permissions/index.html @@ -543,7 +543,7 @@ class IsOwnerOrReadOnly(permissions.BasePermission): # Write permissions are only allowed to the owner of the snippet. return obj.owner == request.user </code></pre> -<p>Now we can add that custom permission to our snippet instance endpoint, by editing the <code>permission_classes</code> property on the <code>SnippetDetail</code> class:</p> +<p>Now we can add that custom permission to our snippet instance endpoint, by editing the <code>permission_classes</code> property on the <code>SnippetDetail</code> view class:</p> <pre><code>permission_classes = (permissions.IsAuthenticatedOrReadOnly, IsOwnerOrReadOnly,) </code></pre> diff --git a/tutorial/5-relationships-and-hyperlinked-apis/index.html b/tutorial/5-relationships-and-hyperlinked-apis/index.html index 0d82b190..39b8dd42 100644 --- a/tutorial/5-relationships-and-hyperlinked-apis/index.html +++ b/tutorial/5-relationships-and-hyperlinked-apis/index.html @@ -482,7 +482,9 @@ class UserSerializer(serializers.HyperlinkedModelSerializer): <li>Our snippet and user serializers include <code>'url'</code> fields that by default will refer to <code>'{model_name}-detail'</code>, which in this case will be <code>'snippet-detail'</code> and <code>'user-detail'</code>.</li> </ul> <p>After adding all those names into our URLconf, our final <code>snippets/urls.py</code> file should look something like this:</p> -<pre><code># API endpoints +<pre><code>from django.conf.urls import url, include + +# API endpoints urlpatterns = format_suffix_patterns([ url(r'^$', views.api_root), url(r'^snippets/$', |
