Code

Ticket #13538: 13538.diff

File 13538.diff, 1.5 KB (added by dwillis, 4 years ago)
Line 
1From 6667a5dff0658801f6c6b8c23b514924937b70c6 Mon Sep 17 00:00:00 2001
2From: Derek Willis <dwillis@gmail.com>
3Date: Sun, 1 Aug 2010 21:36:41 -0400
4Subject: [PATCH] Clarified Saving ForeignKey and ManyToManyField fields docs
5
6---
7 docs/topics/db/queries.txt |    9 +++++++--
8 1 files changed, 7 insertions(+), 2 deletions(-)
9
10diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
11index 981d727..7bb66fe 100644
12--- a/docs/topics/db/queries.txt
13+++ b/docs/topics/db/queries.txt
14@@ -97,15 +97,20 @@ Saving ``ForeignKey`` and ``ManyToManyField`` fields
15 ----------------------------------------------------
16 
17 Updating ``ForeignKey`` fields works exactly the same way as saving a normal
18-field; simply assign an object of the right type to the field in question::
19+field; simply assign an object of the right type to the field in question.
20+Given an ``Entry`` instance ``entry``, this example updates its blog attribute::
21 
22+    >>> from mysite.blog.models import Entry
23+    >>> entry = Entry.objects.get(pk=1)
24     >>> cheese_blog = Blog.objects.get(name="Cheddar Talk")
25     >>> entry.blog = cheese_blog
26     >>> entry.save()
27 
28 Updating a ``ManyToManyField`` works a little differently; use the ``add()``
29-method on the field to add a record to the relation::
30+method on the field to add a record to the relation. This example adds the
31+``Author`` instance ``joe`` to the entry object::
32 
33+    >> from mysite.blog.models import Author
34     >> joe = Author.objects.create(name="Joe")
35     >> entry.authors.add(joe)
36 
37--
381.6.5.7
39