1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #25508 -- Modified QuerySet.__repr__() to disambiguate it from a list.

This commit is contained in:
Tim Graham
2015-10-05 19:07:34 -04:00
parent 3543fec3b7
commit e0837f2cb1
20 changed files with 185 additions and 184 deletions

View File

@@ -401,7 +401,7 @@ Once you're in the shell, explore the :doc:`database API </topics/db/queries>`::
# No questions are in the system yet.
>>> Question.objects.all()
[]
<QuerySet []>
# Create a new Question.
# Support for time zones is enabled in the default settings file, so
@@ -432,8 +432,7 @@ Once you're in the shell, explore the :doc:`database API </topics/db/queries>`::
# objects.all() displays all the questions in the database.
>>> Question.objects.all()
[<Question: Question object>]
<QuerySet [<Question: Question object>]>
Wait a minute. ``<Question: Question object>`` is, utterly, an unhelpful representation
of this object. Let's fix that by editing the ``Question`` model (in the
@@ -494,14 +493,14 @@ Save these changes and start a new Python interactive shell by running
# Make sure our __str__() addition worked.
>>> Question.objects.all()
[<Question: What's up?>]
<QuerySet [<Question: What's up?>]>
# Django provides a rich database lookup API that's entirely driven by
# keyword arguments.
>>> Question.objects.filter(id=1)
[<Question: What's up?>]
<QuerySet [<Question: What's up?>]>
>>> Question.objects.filter(question_text__startswith='What')
[<Question: What's up?>]
<QuerySet [<Question: What's up?>]>
# Get the question that was published this year.
>>> from django.utils import timezone
@@ -535,7 +534,7 @@ Save these changes and start a new Python interactive shell by running
# Display any choices from the related object set -- none so far.
>>> q.choice_set.all()
[]
<QuerySet []>
# Create three choices.
>>> q.choice_set.create(choice_text='Not much', votes=0)
@@ -550,7 +549,7 @@ Save these changes and start a new Python interactive shell by running
# And vice versa: Question objects get access to Choice objects.
>>> q.choice_set.all()
[<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]
<QuerySet [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]>
>>> q.choice_set.count()
3
@@ -560,7 +559,7 @@ Save these changes and start a new Python interactive shell by running
# Find all Choices for any question whose pub_date is in this year
# (reusing the 'current_year' variable we created above).
>>> Choice.objects.filter(question__pub_date__year=current_year)
[<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]
<QuerySet [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]>
# Let's delete one of the choices. Use delete() for that.
>>> c = q.choice_set.filter(choice_text__startswith='Just hacking')