Ticket #13538: 13538.diff

File 13538.diff, 1.5 KB (added by Derek Willis, 14 years ago)
  • docs/topics/db/queries.txt

    From 6667a5dff0658801f6c6b8c23b514924937b70c6 Mon Sep 17 00:00:00 2001
    From: Derek Willis <dwillis@gmail.com>
    Date: Sun, 1 Aug 2010 21:36:41 -0400
    Subject: [PATCH] Clarified Saving ForeignKey and ManyToManyField fields docs
    
    ---
     docs/topics/db/queries.txt |    9 +++++++--
     1 files changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
    index 981d727..7bb66fe 100644
    a b Saving ``ForeignKey`` and ``ManyToManyField`` fields  
    9797----------------------------------------------------
    9898
    9999Updating ``ForeignKey`` fields works exactly the same way as saving a normal
    100 field; simply assign an object of the right type to the field in question::
     100field; simply assign an object of the right type to the field in question.
     101Given an ``Entry`` instance ``entry``, this example updates its blog attribute::
    101102
     103    >>> from mysite.blog.models import Entry
     104    >>> entry = Entry.objects.get(pk=1)
    102105    >>> cheese_blog = Blog.objects.get(name="Cheddar Talk")
    103106    >>> entry.blog = cheese_blog
    104107    >>> entry.save()
    105108
    106109Updating a ``ManyToManyField`` works a little differently; use the ``add()``
    107 method on the field to add a record to the relation::
     110method on the field to add a record to the relation. This example adds the
     111``Author`` instance ``joe`` to the entry object::
    108112
     113    >> from mysite.blog.models import Author
    109114    >> joe = Author.objects.create(name="Joe")
    110115    >> entry.authors.add(joe)
    111116
Back to Top