mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-14 21:56:59 +03:00
Docs: Removed (potential confusing) dot ".
method()" (#6145)
This commit is contained in:
parent
43c6800f3a
commit
8e48be4343
|
@ -520,7 +520,7 @@ url(r'^users/(?P<pk>[0-9]+)/$', views.UserDetail.as_view()),
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<h2 id="associating-snippets-with-users"><a class="toclink" href="#associating-snippets-with-users">Associating Snippets with Users</a></h2>
|
<h2 id="associating-snippets-with-users"><a class="toclink" href="#associating-snippets-with-users">Associating Snippets with Users</a></h2>
|
||||||
<p>Right now, if we created a code snippet, there'd be no way of associating the user that created the snippet, with the snippet instance. The user isn't sent as part of the serialized representation, but is instead a property of the incoming request.</p>
|
<p>Right now, if we created a code snippet, there'd be no way of associating the user that created the snippet, with the snippet instance. The user isn't sent as part of the serialized representation, but is instead a property of the incoming request.</p>
|
||||||
<p>The way we deal with that is by overriding a <code>.perform_create()</code> method on our snippet views, that allows us to modify how the instance save is managed, and handle any information that is implicit in the incoming request or requested URL.</p>
|
<p>The way we deal with that is by overriding a <code>perform_create()</code> method on our snippet views, that allows us to modify how the instance save is managed, and handle any information that is implicit in the incoming request or requested URL.</p>
|
||||||
<p>On the <code>SnippetList</code> view class, add the following method:</p>
|
<p>On the <code>SnippetList</code> view class, add the following method:</p>
|
||||||
<pre><code>def perform_create(self, serializer):
|
<pre><code>def perform_create(self, serializer):
|
||||||
serializer.save(owner=self.request.user)
|
serializer.save(owner=self.request.user)
|
||||||
|
@ -660,4 +660,4 @@ class IsOwnerOrReadOnly(permissions.BasePermission):
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user