diff options
Diffstat (limited to 'docs/tutorial01.txt')
| -rw-r--r-- | docs/tutorial01.txt | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/docs/tutorial01.txt b/docs/tutorial01.txt index 03d4eac635..c353e1ab4b 100644 --- a/docs/tutorial01.txt +++ b/docs/tutorial01.txt @@ -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') |
