Author: gabrielhurley
Date: 2010-10-09 03:26:29 -0500 (Sat, 09 Oct 2010)
New Revision: 14073

Modified:
   django/branches/releases/1.2.X/docs/topics/db/queries.txt
Log:
[1.2.X] Fixed #13538 -- Clarified query examples with more explicit import 
statements and model vs. instance differentiation. Thanks to yipengh87 and 
kmtracey for the report, and timo for the patch.

Backport of [14070] from trunk.

Modified: django/branches/releases/1.2.X/docs/topics/db/queries.txt
===================================================================
--- django/branches/releases/1.2.X/docs/topics/db/queries.txt   2010-10-09 
08:25:01 UTC (rev 14072)
+++ django/branches/releases/1.2.X/docs/topics/db/queries.txt   2010-10-09 
08:26:29 UTC (rev 14073)
@@ -94,18 +94,23 @@
 Saving ``ForeignKey`` and ``ManyToManyField`` fields
 ----------------------------------------------------
 
-Updating ``ForeignKey`` fields works exactly the same way as saving a normal
-field; simply assign an object of the right type to the field in question::
+Updating a ``ForeignKey`` field works exactly the same way as saving a normal
+field; simply assign an object of the right type to the field in question.
+This example updates the ``blog`` attribute of an ``Entry`` instance 
``entry``::
 
+    >>> from mysite.blog.models import Entry
+    >>> entry = Entry.objects.get(pk=1)
     >>> cheese_blog = Blog.objects.get(name="Cheddar Talk")
     >>> entry.blog = cheese_blog
     >>> entry.save()
 
 Updating a ``ManyToManyField`` works a little differently; use the ``add()``
-method on the field to add a record to the relation::
+method on the field to add a record to the relation. This example adds the
+``Author`` instance ``joe`` to the ``entry`` object::
 
-    >> joe = Author.objects.create(name="Joe")
-    >> entry.authors.add(joe)
+    >>> from mysite.blog.models import Author
+    >>> joe = Author.objects.create(name="Joe")
+    >>> entry.authors.add(joe)
 
 Django will complain if you try to assign or add an object of the wrong type.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to