Django

Code

Changeset 6010

Show
Ignore:
Timestamp:
08/25/07 13:58:36 (1 year ago)
Author:
adrian
Message:

Fixed #5068 -- Fixed error in docs/db-api.txt. Thanks, Collin Grady and SmileyChris?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/db-api.txt

    r5803 r6010  
    208208The ``save()`` method has no return value. 
    209209 
    210 Updating ``ForeignKey`` fields works exactly the same way; simply assign an 
    211 object of the right type to the field in question:: 
     210Saving ForeignKey and ManyToManyField fields 
     211-------------------------------------------- 
     212 
     213Updating ``ForeignKey`` fields works exactly the same way as saving a normal 
     214field; 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 
     220Updating a ``ManyToManyField`` works a little differently; use the ``add()`` 
     221method on the field to add a record to the relation:: 
    212222 
    213223    joe = Author.objects.create(name="Joe") 
    214     entry.author = joe 
    215     entry.save() 
    216  
    217 Django will complain if you try to assign an object of the wrong type
     224    entry.authors.add(joe) 
     225 
     226Django will complain if you try to assign or add an object of the wrong type. 
     227You can find out more about `Queries over related objects`_ below
    218228 
    219229How Django knows to UPDATE vs. INSERT