Added Prefetch import to first use in QuerySet docs.
This commit is contained in:
parent
adb791fdcb
commit
3be2268992
|
@ -1084,6 +1084,7 @@ the prefetch operation.
|
||||||
In its simplest form ``Prefetch`` is equivalent to the traditional string based
|
In its simplest form ``Prefetch`` is equivalent to the traditional string based
|
||||||
lookups:
|
lookups:
|
||||||
|
|
||||||
|
>>> from django.db.models import Prefetch
|
||||||
>>> Restaurant.objects.prefetch_related(Prefetch('pizzas__toppings'))
|
>>> Restaurant.objects.prefetch_related(Prefetch('pizzas__toppings'))
|
||||||
|
|
||||||
You can provide a custom queryset with the optional ``queryset`` argument.
|
You can provide a custom queryset with the optional ``queryset`` argument.
|
||||||
|
@ -3138,6 +3139,7 @@ The ``lookup`` argument describes the relations to follow and works the same
|
||||||
as the string based lookups passed to
|
as the string based lookups passed to
|
||||||
:meth:`~django.db.models.query.QuerySet.prefetch_related()`. For example:
|
:meth:`~django.db.models.query.QuerySet.prefetch_related()`. For example:
|
||||||
|
|
||||||
|
>>> from django.db.models import Prefetch
|
||||||
>>> Question.objects.prefetch_related(Prefetch('choice_set')).get().choice_set.all()
|
>>> Question.objects.prefetch_related(Prefetch('choice_set')).get().choice_set.all()
|
||||||
<QuerySet [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]>
|
<QuerySet [<Choice: Not much>, <Choice: The sky>, <Choice: Just hacking again>]>
|
||||||
# This will only execute two queries regardless of the number of Question
|
# This will only execute two queries regardless of the number of Question
|
||||||
|
|
Loading…
Reference in New Issue