From ffdf633aa53526d2868e485ecffe0411a4ce0874 Mon Sep 17 00:00:00 2001 From: Areski Belaid Date: Wed, 5 Jun 2013 14:19:36 +0200 Subject: Fix on documentation - wrong reference at previous created view UserList / UserDetail --- docs/tutorial/6-viewsets-and-routers.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index 4ed10e82..d40ef781 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -10,7 +10,9 @@ A `ViewSet` class is only bound to a set of method handlers at the last moment, Let's take our current set of views, and refactor them into view sets. -First of all let's refactor our `UserListView` and `UserDetailView` views into a single `UserViewSet`. We can remove the two views, and replace then with a single class: +First of all let's refactor our `UserList` and `UserDetail` views into a single `UserViewSet`. We can remove the two views, and replace then with a single class: + + from rest_framework import viewsets class UserViewSet(viewsets.ReadOnlyModelViewSet): """ @@ -23,15 +25,14 @@ Here we've used `ReadOnlyModelViewSet` class to automatically provide the defaul Next we're going to replace the `SnippetList`, `SnippetDetail` and `SnippetHighlight` view classes. We can remove the three views, and again replace them with a single class. - from rest_framework import viewsets from rest_framework.decorators import link class SnippetViewSet(viewsets.ModelViewSet): """ This viewset automatically provides `list`, `create`, `retrieve`, `update` and `destroy` actions. - - Additionally we also provide an extra `highlight` action. + + Additionally we also provide an extra `highlight` action. """ queryset = Snippet.objects.all() serializer_class = SnippetSerializer @@ -107,7 +108,7 @@ Here's our re-wired `urls.py` file. router = DefaultRouter() router.register(r'snippets', views.SnippetViewSet) router.register(r'users', views.UserViewSet) - + # The API URLs are now determined automatically by the router. # Additionally, we include the login URLs for the browseable API. urlpatterns = patterns('', @@ -131,7 +132,7 @@ With an incredibly small amount of code, we've now got a complete pastebin Web A We've walked through each step of the design process, and seen how if we need to customize anything we can gradually work our way down to simply using regular Django views. -You can review the final [tutorial code][repo] on GitHub, or try out a live example in [the sandbox][sandbox]. +You can review the final [tutorial code][repo] on GitHub, or try out a live example in [the sandbox][sandbox]. ## Onwards and upwards -- cgit v1.2.3 From f317699d47e89882ee446ebec0388a1444223754 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 5 Jun 2013 14:36:40 +0200 Subject: Added @areski for docs fix #912. Thanks! --- docs/topics/credits.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs') diff --git a/docs/topics/credits.md b/docs/topics/credits.md index bbe209c7..db522922 100644 --- a/docs/topics/credits.md +++ b/docs/topics/credits.md @@ -139,6 +139,7 @@ The following people have helped make REST framework great. * Pascal Borreli - [pborreli] * Alex Burgel - [aburgel] * David Medina - [copitux] +* Areski Belaid - [areski] Many thanks to everyone who's contributed to the project. @@ -314,3 +315,4 @@ You can also contact [@_tomchristie][twitter] directly on twitter. [pborreli]: https://github.com/pborreli [aburgel]: https://github.com/aburgel [copitux]: https://github.com/copitux +[areski]: https://github.com/areski -- cgit v1.2.3 From fdb689f9b552f219dd677b3b8421ceebcfd5b1e2 Mon Sep 17 00:00:00 2001 From: gnunamed Date: Wed, 5 Jun 2013 13:53:00 -0500 Subject: Update serializers.md --- docs/api-guide/serializers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 71f0abb7..9b6a547f 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -39,7 +39,7 @@ Declaring a serializer looks very similar to declaring a form: an existing model instance, or create a new model instance. """ if instance is not None: - instance.title = attrs.get('title', instance.title) + instance.email = attrs.get('email', instance.email) instance.content = attrs.get('content', instance.content) instance.created = attrs.get('created', instance.created) return instance -- cgit v1.2.3 From 40e09472d8b32988ef8284f66569cd26b3204ac6 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 6 Jun 2013 08:56:39 +0100 Subject: Never deepcopy validators. Closes #913 --- docs/api-guide/generic-views.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index 20b9440b..c8216954 100755 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -131,7 +131,7 @@ You may want to override this method to provide more complex behavior such as mo For example: def get_paginate_by(self): - self.request.accepted_renderer.format == 'html': + if self.request.accepted_renderer.format == 'html': return 20 return 100 -- cgit v1.2.3 From e483c4fed686d7e3c7787d2e3eaa5ec4665399ff Mon Sep 17 00:00:00 2001 From: Ryan Kaskel Date: Fri, 7 Jun 2013 10:07:42 +0100 Subject: Remove pass statement before docstring. --- docs/api-guide/viewsets.md | 2 -- 1 file changed, 2 deletions(-) (limited to 'docs') diff --git a/docs/api-guide/viewsets.md b/docs/api-guide/viewsets.md index 2783da98..79257e2a 100644 --- a/docs/api-guide/viewsets.md +++ b/docs/api-guide/viewsets.md @@ -209,8 +209,6 @@ To create a base viewset class that provides `create`, `list` and `retrieve` ope mixins.ListMixin, mixins.RetrieveMixin, viewsets.GenericViewSet): - pass - """ A viewset that provides `retrieve`, `update`, and `list` actions. -- cgit v1.2.3 From 5ce1d6c86bb0831916ba4137560d84295ac7ec95 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Sat, 8 Jun 2013 09:38:21 +0200 Subject: Added @mindlace for work on #922. Thx! --- docs/topics/credits.md | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs') diff --git a/docs/topics/credits.md b/docs/topics/credits.md index db522922..b4bd3561 100644 --- a/docs/topics/credits.md +++ b/docs/topics/credits.md @@ -140,6 +140,7 @@ The following people have helped make REST framework great. * Alex Burgel - [aburgel] * David Medina - [copitux] * Areski Belaid - [areski] +* Ethan Freman - [mindlace] Many thanks to everyone who's contributed to the project. @@ -316,3 +317,4 @@ You can also contact [@_tomchristie][twitter] directly on twitter. [aburgel]: https://github.com/aburgel [copitux]: https://github.com/copitux [areski]: https://github.com/areski +[mindlace]: https://github.com/mindlace -- cgit v1.2.3 From 777ecb5141d5d4f1a6b4e10e376965148022822c Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 10 Jun 2013 09:05:44 +0100 Subject: Add renderer_classes kwarg when binding snippet_highlight explicitly. Closes #923 --- docs/tutorial/6-viewsets-and-routers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index d40ef781..f16add39 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -74,7 +74,7 @@ In the `urls.py` file we bind our `ViewSet` classes into a set of concrete views }) snippet_highlight = SnippetViewSet.as_view({ 'get': 'highlight' - }) + }, renderer_classes=[renderers.StaticHTMLRenderer]) user_list = UserViewSet.as_view({ 'get': 'list' }) -- cgit v1.2.3 From 5d0aeef69ecec70242513195c19edcb622e14371 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 10 Jun 2013 17:46:55 +0100 Subject: Better docs related to lookup_field and hyperlinked serializers. Closes #920. --- docs/api-guide/generic-views.md | 2 +- docs/api-guide/serializers.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md index c8216954..cd1bc7a1 100755 --- a/docs/api-guide/generic-views.md +++ b/docs/api-guide/generic-views.md @@ -60,7 +60,7 @@ The following attributes control the basic view behavior. * `queryset` - The queryset that should be used for returning objects from this view. Typically, you must either set this attribute, or override the `get_queryset()` method. * `serializer_class` - The serializer class that should be used for validating and deserializing input, and for serializing output. Typically, you must either set this attribute, or override the `get_serializer_class()` method. -* `lookup_field` - The field that should be used to lookup individual model instances. Defaults to `'pk'`. The URL conf should include a keyword argument corresponding to this value. More complex lookup styles can be supported by overriding the `get_object()` method. +* `lookup_field` - The field that should be used to lookup individual model instances. Defaults to `'pk'`. The URL conf should include a keyword argument corresponding to this value. More complex lookup styles can be supported by overriding the `get_object()` method. Note that when using hyperlinked APIs you'll need to ensure that *both* the API views *and* the serializer classes use lookup fields that correctly correspond with the URL conf. **Shortcuts**: diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index 9b6a547f..0885eb52 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -387,7 +387,7 @@ There needs to be a way of determining which views should be used for hyperlinki By default hyperlinks are expected to correspond to a view name that matches the style `'{model_name}-detail'`, and looks up the instance by a `pk` keyword argument. -You can change the field that is used for object lookups by setting the `lookup_field` option. The value of this option should correspond both with a kwarg in the URL conf, and with an field on the model. For example: +You can change the field that is used for object lookups by setting the `lookup_field` option. The value of this option should correspond both with a kwarg in the URL conf, and with a field on the model. For example: class AccountSerializer(serializers.HyperlinkedModelSerializer): class Meta: @@ -395,6 +395,8 @@ You can change the field that is used for object lookups by setting the `lookup_ fields = ('url', 'account_name', 'users', 'created') lookup_field = 'slug' +Not that the `lookup_field` will be used as the default on *all* hyperlinked fields, including both the URL identity, and any hyperlinked relationships. + For more specfic requirements such as specifying a different lookup for each field, you'll want to set the fields on the serializer explicitly. For example: class AccountSerializer(serializers.HyperlinkedModelSerializer): -- cgit v1.2.3 From 1cc2a7b25e78fcb41f44dc5b580f0f00a0a6318a Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 12 Jun 2013 22:46:07 +0200 Subject: Added @davesque for work on #926. Thanks! :) --- docs/topics/credits.md | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs') diff --git a/docs/topics/credits.md b/docs/topics/credits.md index b4bd3561..3f0ee429 100644 --- a/docs/topics/credits.md +++ b/docs/topics/credits.md @@ -141,6 +141,7 @@ The following people have helped make REST framework great. * David Medina - [copitux] * Areski Belaid - [areski] * Ethan Freman - [mindlace] +* David Sanders - [davesque] Many thanks to everyone who's contributed to the project. @@ -318,3 +319,5 @@ You can also contact [@_tomchristie][twitter] directly on twitter. [copitux]: https://github.com/copitux [areski]: https://github.com/areski [mindlace]: https://github.com/mindlace +[davesque]: https://github.com/davesque + -- cgit v1.2.3