Minor tutorial updates

This commit is contained in:
Tom Christie 2016-07-14 12:44:13 +01:00
parent aa40c58381
commit a9218e460f
2 changed files with 12 additions and 7 deletions

View File

@ -80,7 +80,7 @@ We can easily re-write our existing serializers to use hyperlinking. In your `sn
class Meta: class Meta:
model = Snippet model = Snippet
fields = ('url', 'highlight', 'owner', fields = ('url', 'pk', 'highlight', 'owner',
'title', 'code', 'linenos', 'language', 'style') 'title', 'code', 'linenos', 'language', 'style')
@ -89,7 +89,7 @@ We can easily re-write our existing serializers to use hyperlinking. In your `sn
class Meta: class Meta:
model = User model = User
fields = ('url', 'username', 'snippets') fields = ('url', 'pk', 'username', 'snippets')
Notice that we've also added a new `'highlight'` field. This field is of the same type as the `url` field, except that it points to the `'snippet-highlight'` url pattern, instead of the `'snippet-detail'` url pattern. Notice that we've also added a new `'highlight'` field. This field is of the same type as the `url` field, except that it points to the `'snippet-highlight'` url pattern, instead of the `'snippet-detail'` url pattern.

View File

@ -67,9 +67,13 @@ also supported.
Now that our API is exposing a schema endpoint, we can use a dynamic client Now that our API is exposing a schema endpoint, we can use a dynamic client
library to interact with the API. To demonstrate this, let's use the library to interact with the API. To demonstrate this, let's use the
Core API command line client. We've already installed the `coreapi` package Core API command line client.
using `pip`, so the client tool should already be installed. Check that it
is available on the command line... The command line client is available as the `coreapi-cli` package:
$ pip install coreapi-cli
Now check that it is available on the command line...
$ coreapi $ coreapi
Usage: coreapi [OPTIONS] COMMAND [ARGS]... Usage: coreapi [OPTIONS] COMMAND [ARGS]...
@ -108,6 +112,7 @@ Let's try listing the existing snippets, using the command line client:
[ [
{ {
"url": "http://127.0.0.1:8000/snippets/1/", "url": "http://127.0.0.1:8000/snippets/1/",
"pk": 1,
"highlight": "http://127.0.0.1:8000/snippets/1/highlight/", "highlight": "http://127.0.0.1:8000/snippets/1/highlight/",
"owner": "lucy", "owner": "lucy",
"title": "Example", "title": "Example",
@ -166,7 +171,7 @@ snippet:
$ coreapi action snippets create --param title "Example" --param code "print('hello, world')" $ coreapi action snippets create --param title "Example" --param code "print('hello, world')"
{ {
"url": "http://127.0.0.1:8000/snippets/7/", "url": "http://127.0.0.1:8000/snippets/7/",
"id": 7, "pk": 7,
"highlight": "http://127.0.0.1:8000/snippets/7/highlight/", "highlight": "http://127.0.0.1:8000/snippets/7/highlight/",
"owner": "lucy", "owner": "lucy",
"title": "Example", "title": "Example",