Ticket #12114: 12114.patch

File 12114.patch, 2.1 KB (added by Derek Willis, 15 years ago)
  • docs/intro/tutorial01.txt

    From f7753c4512ca4b6fc0cf976b82bf153f74d3486b Mon Sep 17 00:00:00 2001
    From: Derek Willis <dwillis@gmail.com>
    Date: Sat, 27 Feb 2010 23:21:08 -0500
    Subject: [PATCH] stab at related objects in tutorial 1
    
    ---
     docs/intro/tutorial01.txt |   17 +++++++++++++----
     1 files changed, 13 insertions(+), 4 deletions(-)
    
    diff --git a/docs/intro/tutorial01.txt b/docs/intro/tutorial01.txt
    index df9dac6..e76ec69 100644
    a b Save these changes and start a new Python interactive shell by running  
    656656
    657657    # Give the Poll a couple of Choices. The create call constructs a new
    658658    # choice object, does the INSERT statement, adds the choice to the set
    659     # of available choices and returns the new Choice object.
     659    # of available choices and returns the new Choice object. Django creates
     660    # a set to hold the "other side" of a ForeignKey relation (e.g. a poll's choices)
     661    # which can be accessed via the API.
    660662    >>> p = Poll.objects.get(pk=1)
     663   
     664    # Display any choices from the related object set.
     665    >>> p.choice_set.all()
     666    []
     667   
     668    # Create three choices.
    661669    >>> p.choice_set.create(choice='Not much', votes=0)
    662670    <Choice: Not much>
    663671    >>> p.choice_set.create(choice='The sky', votes=0)
    664672    <Choice: The sky>
    665673    >>> c = p.choice_set.create(choice='Just hacking again', votes=0)
    666 
     674   
    667675    # Choice objects have API access to their related Poll objects.
    668676    >>> c.poll
    669677    <Poll: What's up?>
    Save these changes and start a new Python interactive shell by running  
    685693    >>> c = p.choice_set.filter(choice__startswith='Just hacking')
    686694    >>> c.delete()
    687695
    688 For full details on the database API, see our :ref:`Database API reference
    689 <topics-db-queries>`.
     696For more information on model relations, see :ref:`Accessing related objects
     697<ref-models-relations>`. For full details on the database API, see our
     698:ref:`Database API reference <topics-db-queries>`.
    690699
    691700When you're comfortable with the API, read :ref:`part 2 of this tutorial
    692701<intro-tutorial02>` to get Django's automatic admin working.
Back to Top