aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2012-10-30 11:55:02 +0000
committerTom Christie2012-10-30 11:55:02 +0000
commit29bc52096a40c3f483e763cf562815ded3e56faa (patch)
tree72b985e210c84697cab75c08a4ad2d1a521cda37
parentcea907f172c4f640e8bb44e14fab43150fbbc6ad (diff)
downloaddjango-rest-framework-29bc52096a40c3f483e763cf562815ded3e56faa.tar.bz2
Docs tweaks for tutorial.
-rw-r--r--docs/tutorial/5-relationships-and-hyperlinked-apis.md18
1 files changed, 17 insertions, 1 deletions
diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md
index 38e32157..777aa5e1 100644
--- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md
+++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md
@@ -74,7 +74,7 @@ We can easily re-write our existing serializers to use hyperlinking.
class SnippetSerializer(serializers.HyperlinkedModelSerializer):
owner = serializers.Field(source='owner.username')
- highlight = serializers.HyperlinkedIdentityField(view_name='snippet-highlight')
+ highlight = serializers.HyperlinkedIdentityField(view_name='snippet-highlight', format='html')
class Meta:
model = models.Snippet
@@ -91,6 +91,8 @@ We can easily re-write our existing serializers to use hyperlinking.
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.
+Because we've included format suffixed URLs such as `'.json'`, we also need to indicate on the `highlight` field that any format suffixed hyperlinks it returns should use the `'.html'` suffix.
+
## Making sure our URL patterns are named
If we're going to have a hyperlinked API, we need to make sure we name our URL patterns. Let's take a look at which URL patterns we need to name.
@@ -128,6 +130,20 @@ After adding all those names into our URLconf, our final `'urls.py'` file should
namespace='rest_framework'))
)
+## Adding pagination
+
+The list views for users and code snippets could end up returning quite a lot of instances, so really we'd like to make sure we paginate the results, and allow the API client to step through each of the individual pages.
+
+We can change the default list style to use pagination, by modifying our `settings.py` file slightly. Add the following setting:
+
+ REST_FRAMEWORK = {
+ 'PAGINATE_BY': 10
+ }
+
+Note that settings in REST framework are all namespaced into a single dictionary setting, named 'REST_FRAMEWORK', which helps keep them well seperated from your other project settings.
+
+We could also customize the pagination style if we needed too, but in this case we'll just stick with the default.
+
## Reviewing our work
If we open a browser and navigate to the browseable API, you'll find that you can now work your way around the API simply by following links.