summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2022-02-22 09:29:38 +0000
committerGitHub <noreply@github.com>2022-02-22 10:29:38 +0100
commit847f46e9bf88964484c8b76a10af753ea1018311 (patch)
tree13aced534cbae373f47cce8fce1444ad0e8e01d3 /docs
parent7ba6ebe9149ae38257d70100e8bfbfd0da189862 (diff)
Removed redundant QuerySet.all() calls in docs and tests.
Most QuerySet methods are mapped onto the Manager and, in general, it isn't necessary to call .all() on the manager.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/expressions.txt2
-rw-r--r--docs/ref/models/querysets.txt6
-rw-r--r--docs/topics/db/aggregation.txt6
-rw-r--r--docs/topics/db/multi-db.txt4
-rw-r--r--docs/topics/db/queries.txt4
5 files changed, 11 insertions, 11 deletions
diff --git a/docs/ref/models/expressions.txt b/docs/ref/models/expressions.txt
index 208b810048..60c4c87dcd 100644
--- a/docs/ref/models/expressions.txt
+++ b/docs/ref/models/expressions.txt
@@ -156,7 +156,7 @@ the field value on multiple objects - which could be very much faster than
pulling them all into Python from the database, looping over them, incrementing
the field value of each one, and saving each one back to the database::
- Reporter.objects.all().update(stories_filed=F('stories_filed') + 1)
+ Reporter.objects.update(stories_filed=F('stories_filed') + 1)
``F()`` therefore can offer performance advantages by:
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index 25252b9cec..44950ecf52 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -1110,7 +1110,7 @@ item in the Pizza ``QuerySet``.
We can reduce to just two queries using ``prefetch_related``:
- >>> Pizza.objects.all().prefetch_related('toppings')
+ >>> Pizza.objects.prefetch_related('toppings')
This implies a ``self.toppings.all()`` for each ``Pizza``; now each time
``self.toppings.all()`` is called, instead of having to go to the database for
@@ -1648,7 +1648,7 @@ one, doing so will result in an error.
# Two equivalent QuerySets:
CommonlyUsedModel.objects.all()
- ManagedModel.objects.all().defer('f2')
+ ManagedModel.objects.defer('f2')
If many fields need to be duplicated in the unmanaged model, it may be best
to create an abstract model with the shared fields and then have the
@@ -3771,7 +3771,7 @@ as the string based lookups passed to
<QuerySet [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]>
# This will only execute two queries regardless of the number of Question
# and Choice objects.
- >>> Question.objects.prefetch_related(Prefetch('choice_set')).all()
+ >>> Question.objects.prefetch_related(Prefetch('choice_set'))
<QuerySet [<Question: What's up?>]>
The ``queryset`` argument supplies a base ``QuerySet`` for the given lookup.
diff --git a/docs/topics/db/aggregation.txt b/docs/topics/db/aggregation.txt
index 772de0abdb..42be569cb4 100644
--- a/docs/topics/db/aggregation.txt
+++ b/docs/topics/db/aggregation.txt
@@ -56,12 +56,12 @@ above::
# Average price across all books.
>>> from django.db.models import Avg
- >>> Book.objects.all().aggregate(Avg('price'))
+ >>> Book.objects.aggregate(Avg('price'))
{'price__avg': 34.35}
# Max price across all books.
>>> from django.db.models import Max
- >>> Book.objects.all().aggregate(Max('price'))
+ >>> Book.objects.aggregate(Max('price'))
{'price__max': Decimal('81.20')}
# Difference between the highest priced book and the average price of all books.
@@ -111,7 +111,7 @@ belong to this ``QuerySet``. This is done by appending an ``aggregate()``
clause onto the ``QuerySet``::
>>> from django.db.models import Avg
- >>> Book.objects.all().aggregate(Avg('price'))
+ >>> Book.objects.aggregate(Avg('price'))
{'price__avg': 34.35}
The ``all()`` is redundant in this example, so this could be simplified to::
diff --git a/docs/topics/db/multi-db.txt b/docs/topics/db/multi-db.txt
index d74972b0e0..cf7d6fef4f 100644
--- a/docs/topics/db/multi-db.txt
+++ b/docs/topics/db/multi-db.txt
@@ -459,10 +459,10 @@ which you want to run the query. For example::
>>> Author.objects.all()
>>> # So will this.
- >>> Author.objects.using('default').all()
+ >>> Author.objects.using('default')
>>> # This will run on the 'other' database.
- >>> Author.objects.using('other').all()
+ >>> Author.objects.using('other')
Selecting a database for ``save()``
-----------------------------------
diff --git a/docs/topics/db/queries.txt b/docs/topics/db/queries.txt
index 23326fb778..9e45f66bb5 100644
--- a/docs/topics/db/queries.txt
+++ b/docs/topics/db/queries.txt
@@ -1327,7 +1327,7 @@ new value to be the new model instance you want to point to. For example::
>>> b = Blog.objects.get(pk=1)
# Change every Entry so that it belongs to this Blog.
- >>> Entry.objects.all().update(blog=b)
+ >>> Entry.objects.update(blog=b)
The ``update()`` method is applied instantly and returns the number of rows
matched by the query (which may not be equal to the number of rows updated if
@@ -1361,7 +1361,7 @@ update one field based on the value of another field in the model. This is
especially useful for incrementing counters based upon their current value. For
example, to increment the pingback count for every entry in the blog::
- >>> Entry.objects.all().update(number_of_pingbacks=F('number_of_pingbacks') + 1)
+ >>> Entry.objects.update(number_of_pingbacks=F('number_of_pingbacks') + 1)
However, unlike ``F()`` objects in filter and exclude clauses, you can't
introduce joins when you use ``F()`` objects in an update -- you can only