Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5068 -- Fixed error in docs/db-api.txt. Thanks, Collin Grady a…

…nd SmileyChris

git-svn-id: http://code.djangoproject.com/svn/django/trunk@6010 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b189e266ef1a4f8c3fba39e44e053ec42fc52098 1 parent 861b28f
Adrian Holovaty authored August 25, 2007

Showing 1 changed file with 15 additions and 5 deletions. Show diff stats Hide diff stats

  1. 20  docs/db-api.txt
20  docs/db-api.txt
@@ -207,14 +207,24 @@ the database until you explicitly call ``save()``.
207 207
 
208 208
 The ``save()`` method has no return value.
209 209
 
210  
-Updating ``ForeignKey`` fields works exactly the same way; simply assign an
211  
-object of the right type to the field in question::
  210
+Saving ForeignKey and ManyToManyField fields
  211
+--------------------------------------------
  212
+
  213
+Updating ``ForeignKey`` fields works exactly the same way as saving a normal
  214
+field; simply assign an object of the right type to the field in question:: 
  215
+
  216
+    cheese_blog = Blog.objects.get(name="Cheddar Talk") 
  217
+    entry.blog = cheese_blog 
  218
+    entry.save() 
  219
+
  220
+Updating a ``ManyToManyField`` works a little differently; use the ``add()``
  221
+method on the field to add a record to the relation::
212 222
 
213 223
     joe = Author.objects.create(name="Joe")
214  
-    entry.author = joe
215  
-    entry.save()
  224
+    entry.authors.add(joe)
216 225
 
217  
-Django will complain if you try to assign an object of the wrong type.
  226
+Django will complain if you try to assign or add an object of the wrong type.
  227
+You can find out more about `Queries over related objects`_ below.
218 228
 
219 229
 How Django knows to UPDATE vs. INSERT
220 230
 -------------------------------------

0 notes on commit b189e26

Please sign in to comment.
Something went wrong with that request. Please try again.