summaryrefslogtreecommitdiff
path: root/docs/db-api.txt
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2007-08-25 18:58:36 +0000
committerAdrian Holovaty <adrian@holovaty.com>2007-08-25 18:58:36 +0000
commitb189e266ef1a4f8c3fba39e44e053ec42fc52098 (patch)
tree981cb5c71bea369236a464a0bb45e2742f730fc5 /docs/db-api.txt
parent861b28f37e790e13dfae45da5042588f0ab57b1a (diff)
Fixed #5068 -- Fixed error in docs/db-api.txt. Thanks, Collin Grady and SmileyChris
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6010 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs/db-api.txt')
-rw-r--r--docs/db-api.txt20
1 files changed, 15 insertions, 5 deletions
diff --git a/docs/db-api.txt b/docs/db-api.txt
index 766a6ae519..473a153cb8 100644
--- a/docs/db-api.txt
+++ b/docs/db-api.txt
@@ -207,14 +207,24 @@ the database until you explicitly call ``save()``.
The ``save()`` method has no return value.
-Updating ``ForeignKey`` fields works exactly the same way; simply assign an
-object of the right type to the field in question::
+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::
+
+ 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::
joe = Author.objects.create(name="Joe")
- entry.author = joe
- entry.save()
+ entry.authors.add(joe)
-Django will complain if you try to assign an object of the wrong type.
+Django will complain if you try to assign or add an object of the wrong type.
+You can find out more about `Queries over related objects`_ below.
How Django knows to UPDATE vs. INSERT
-------------------------------------