diff options
| author | Stephan Groß | 2012-11-05 11:45:49 +0100 |
|---|---|---|
| committer | Stephan Groß | 2012-11-05 11:45:49 +0100 |
| commit | 44449fa1f5f2d68740c9fb6a13c8e0a0eb41434c (patch) | |
| tree | c4b6d8ed8af239dd5651d9f6a18ddbfe2079bc07 /docs/tutorial | |
| parent | ff7725f05e8ca624e54d707f7c655e3d5c8b8888 (diff) | |
| parent | 5b397e50ddb999f85949a7359d0a26c3531c78a9 (diff) | |
| download | django-rest-framework-44449fa1f5f2d68740c9fb6a13c8e0a0eb41434c.tar.bz2 | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'docs/tutorial')
| -rw-r--r-- | docs/tutorial/3-class-based-views.md | 4 | ||||
| -rw-r--r-- | docs/tutorial/quickstart.md | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/docs/tutorial/3-class-based-views.md b/docs/tutorial/3-class-based-views.md index a31dccb2..91ef4038 100644 --- a/docs/tutorial/3-class-based-views.md +++ b/docs/tutorial/3-class-based-views.md @@ -92,7 +92,7 @@ Let's take a look at how we can compose our views by using the mixin classes. class SnippetList(mixins.ListModelMixin, mixins.CreateModelMixin, - generics.MultipleObjectBaseView): + generics.MultipleObjectAPIView): model = Snippet serializer_class = SnippetSerializer @@ -102,7 +102,7 @@ Let's take a look at how we can compose our views by using the mixin classes. def post(self, request, *args, **kwargs): return self.create(request, *args, **kwargs) -We'll take a moment to examine exactly what's happening here - We're building our view using `MultipleObjectBaseView`, and adding in `ListModelMixin` and `CreateModelMixin`. +We'll take a moment to examine exactly what's happening here - We're building our view using `MultipleObjectAPIView`, and adding in `ListModelMixin` and `CreateModelMixin`. The base class provides the core functionality, and the mixin classes provide the `.list()` and `.create()` actions. We're then explicitly binding the `get` and `post` methods to the appropriate actions. Simple enough stuff so far. 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" } |
