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
|
656 | 656 | |
657 | 657 | # Give the Poll a couple of Choices. The create call constructs a new |
658 | 658 | # 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. |
660 | 662 | >>> 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. |
661 | 669 | >>> p.choice_set.create(choice='Not much', votes=0) |
662 | 670 | <Choice: Not much> |
663 | 671 | >>> p.choice_set.create(choice='The sky', votes=0) |
664 | 672 | <Choice: The sky> |
665 | 673 | >>> c = p.choice_set.create(choice='Just hacking again', votes=0) |
666 | | |
| 674 | |
667 | 675 | # Choice objects have API access to their related Poll objects. |
668 | 676 | >>> c.poll |
669 | 677 | <Poll: What's up?> |
… |
… |
Save these changes and start a new Python interactive shell by running
|
685 | 693 | >>> c = p.choice_set.filter(choice__startswith='Just hacking') |
686 | 694 | >>> c.delete() |
687 | 695 | |
688 | | For full details on the database API, see our :ref:`Database API reference |
689 | | <topics-db-queries>`. |
| 696 | For 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>`. |
690 | 699 | |
691 | 700 | When you're comfortable with the API, read :ref:`part 2 of this tutorial |
692 | 701 | <intro-tutorial02>` to get Django's automatic admin working. |