Ticket #5068: 5068.2.patch
File 5068.2.patch, 1.2 KB (added by , 17 years ago) |
---|
-
docs/db-api.txt
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 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:: 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 `related objects`_ fields below. 218 228 219 229 How Django knows to UPDATE vs. INSERT 220 230 -------------------------------------