aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/generic-views.md
diff options
context:
space:
mode:
authorTom Christie2013-05-05 16:48:12 +0100
committerTom Christie2013-05-05 16:48:12 +0100
commit2dfd8c9697a1a0ec43a89369ae6a0239ec15b117 (patch)
tree92185a6f02f60b9dae9fe05bea0e13bce453652f /docs/api-guide/generic-views.md
parent660d2405174519628c72ed84a69ae37531df12f3 (diff)
downloaddjango-rest-framework-2dfd8c9697a1a0ec43a89369ae6a0239ec15b117.tar.bz2
docs, docs, docs
Diffstat (limited to 'docs/api-guide/generic-views.md')
-rwxr-xr-xdocs/api-guide/generic-views.md12
1 files changed, 11 insertions, 1 deletions
diff --git a/docs/api-guide/generic-views.md b/docs/api-guide/generic-views.md
index 5de12bdb..d430710d 100755
--- a/docs/api-guide/generic-views.md
+++ b/docs/api-guide/generic-views.md
@@ -125,7 +125,7 @@ For example:
#### `get_paginate_by(self)`
-Returna the page size to use with pagination. By default this uses the `paginate_by` attribute, and may be overridden by the cient if the `paginate_by_param` attribute is set.
+Returns the page size to use with pagination. By default this uses the `paginate_by` attribute, and may be overridden by the cient if the `paginate_by_param` attribute is set.
You may want to override this method to provide more complex behavior such as modifying page sizes based on the media type of the response.
@@ -143,6 +143,16 @@ The following methods are provided as placeholder interfaces. They contain empt
* `pre_save(self, obj)` - A hook that is called before saving an object.
* `post_save(self, obj, created=False)` - A hook that is called after saving an object.
+The `pre_save` method in particular is a useful hook for setting attributes that are implicit in the request, but are not part of the request data. For instance, you might set an attribute on the object based on the request user, or based on a URL keyword argument.
+
+ def pre_save(self, obj):
+ """
+ Set the object's owner, based on the incoming request.
+ """
+ obj.owner = self.request.user
+
+Remember that the `pre_save()` method is not called by `GenericAPIView` itself, but it is called by `create()` and `update()` methods on the `CreateModelMixin` and `UpdateModelMixin` classes.
+
**Other methods**:
You won't typically need to override the following methods, although you might need to call into them if you're writing custom views using `GenericAPIView`.