Fixed #1724 -- updated the output from the shell commands to match what we now

produce.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@2937 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2006-05-18 12:41:24 +00:00
parent 98d6eac81c
commit ce6f058bbb
1 changed files with 16 additions and 16 deletions

View File

@ -445,13 +445,13 @@ Once you're in the shell, explore the database API::
# objects.all() displays all the polls in the database.
>>> Poll.objects.all()
[<Poll object>]
[<Poll: Poll object>]
Wait a minute. ``<Poll object>`` is, utterly, an unhelpful representation of
this object. Let's fix that by editing the polls model
(in the ``polls/models.py`` file) and adding a ``__str__()`` method to
both ``Poll`` and ``Choice``::
Wait a minute. ``<Poll: Poll object>`` is, utterly, an unhelpful
representation of this object. Let's fix that by editing the polls model (in
the ``polls/models.py`` file) and adding a ``__str__()`` method to both
``Poll`` and ``Choice``::
class Poll(models.Model):
# ...
@ -487,30 +487,30 @@ Let's jump back into the Python interactive shell by running
# Make sure our __str__() addition worked.
>>> Poll.objects.all()
[What's up?]
[<Poll: What's up?>]
# Django provides a rich database lookup API that's entirely driven by
# keyword arguments.
>>> Poll.objects.filter(id=1)
[What's up?]
[<Poll: What's up?>]
>>> Poll.objects.filter(question__startswith='What')
[What's up?]
[<Poll: What's up?>]
# Get the poll whose year is 2005. Of course, if you're going through this
# tutorial in another year, change as appropriate.
>>> Poll.objects.get(pub_date__year=2005)
What's up?
<Poll: What's up?>
>>> Poll.objects.get(id=2)
Traceback (most recent call last):
...
DoesNotExist: Poll does not exist for {'id': 2}
DoesNotExist: Poll matching query does not exist.
# Lookup by a primary key is the most common case, so Django provides a
# shortcut for primary-key exact lookups.
# The following is identical to Poll.objects.get(id=1).
>>> Poll.objects.get(pk=1)
What's up?
<Poll: What's up?>
# Make sure our custom method worked.
>>> p = Poll.objects.get(pk=1)
@ -522,18 +522,18 @@ Let's jump back into the Python interactive shell by running
# of available choices and returns the new Choice object.
>>> p = Poll.objects.get(pk=1)
>>> p.choice_set.create(choice='Not much', votes=0)
Not much
<Choice: Not much>
>>> p.choice_set.create(choice='The sky', votes=0)
The sky
<Choice: The sky>
>>> c = p.choice_set.create(choice='Just hacking again', votes=0)
# Choice objects have API access to their related Poll objects.
>>> c.poll
What's up?
<Poll: What's up?>
# And vice versa: Poll objects get access to Choice objects.
>>> p.choice_set.all()
[Not much, The sky, Just hacking again]
[<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]
>>> p.choice_set.count()
3
@ -542,7 +542,7 @@ Let's jump back into the Python interactive shell by running
# This works as many levels deep as you want. There's no limit.
# Find all Choices for any poll whose pub_date is in 2005.
>>> Choice.objects.filter(poll__pub_date__year=2005)
[Not much, The sky, Just hacking again]
[<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]
# Let's delete one of the choices. Use delete() for that.
>>> c = p.choice_set.filter(choice__startswith='Just hacking')