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
This commit is contained in:
parent
861b28f37e
commit
b189e266ef
|
@ -207,14 +207,24 @@ the database until you explicitly call ``save()``.
|
||||||
|
|
||||||
The ``save()`` method has no return value.
|
The ``save()`` method has no return value.
|
||||||
|
|
||||||
Updating ``ForeignKey`` fields works exactly the same way; simply assign an
|
Saving ForeignKey and ManyToManyField fields
|
||||||
object of the right type to the field in question::
|
--------------------------------------------
|
||||||
|
|
||||||
joe = Author.objects.create(name="Joe")
|
Updating ``ForeignKey`` fields works exactly the same way as saving a normal
|
||||||
entry.author = joe
|
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()
|
entry.save()
|
||||||
|
|
||||||
Django will complain if you try to assign an object of the wrong type.
|
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.authors.add(joe)
|
||||||
|
|
||||||
|
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
|
How Django knows to UPDATE vs. INSERT
|
||||||
-------------------------------------
|
-------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue