aboutsummaryrefslogtreecommitdiffstats
path: root/docs/tutorial/quickstart.md
diff options
context:
space:
mode:
authorTom Christie2012-11-01 16:12:42 -0700
committerTom Christie2012-11-01 16:12:42 -0700
commit5209cd1ddaead780d7a4cf610620f4b7bb6b28ab (patch)
tree86097abd5482538c7c026dd233566026b6e6bcad /docs/tutorial/quickstart.md
parent600289a8153eb70542551bab00d59fb7ff0065f0 (diff)
parent36e21153fbc60579c49e46c3f6488ff7bcb1f6ff (diff)
downloaddjango-rest-framework-5209cd1ddaead780d7a4cf610620f4b7bb6b28ab.tar.bz2
Merge pull request #357 from tomchristie/browseable-api-relationships
Relational field support in browseable API.
Diffstat (limited to 'docs/tutorial/quickstart.md')
-rw-r--r--docs/tutorial/quickstart.md9
1 files changed, 8 insertions, 1 deletions
diff --git a/docs/tutorial/quickstart.md b/docs/tutorial/quickstart.md
index 6bde725b..93da1a59 100644
--- a/docs/tutorial/quickstart.md
+++ b/docs/tutorial/quickstart.md
@@ -19,12 +19,19 @@ First up we're going to define some serializers in `quickstart/serializers.py` t
class GroupSerializer(serializers.HyperlinkedModelSerializer):
+ permissions = serializers.ManySlugRelatedField(
+ slug_field='codename',
+ queryset=Permission.objects.all()
+ )
+
class Meta:
model = Group
fields = ('url', 'name', 'permissions')
Notice that we're using hyperlinked relations in this case, with `HyperlinkedModelSerializer`. You can also use primary key and various other relationships, but hyperlinking is good RESTful design.
+We've also overridden the `permission` field on the `GroupSerializer`. In this case we don't want to use a hyperlinked representation, but instead use the list of permission codenames associated with the group, so we've used a `ManySlugRelatedField`, using the `codename` field for the representation.
+
## Views
Right, we'd better write some views then. Open `quickstart/views.py` and get typing.
@@ -152,7 +159,7 @@ We can now access our API, both from the command-line, using tools like `curl`..
},
{
"email": "tom@example.com",
- "groups": [],
+ "groups": [ ],
"url": "http://127.0.0.1:8000/users/2/",
"username": "tom"
}