Ticket #2565: 2565.diff

File 2565.diff, 1.4 KB (added by ubernostrum, 9 years ago)

Patch adding an explanation that all() doesn't query

  • docs/tutorial04.txt

    206206``template_name='polls/results.html'``. Otherwise, both views would use the same
    207207template. Note that we use ``dict()`` to return an altered dictionary in place.
     209.. admonition:: ``all()`` is lazy
     211    It might look a little frightening to see ``Poll.objects.all()``
     212    being used in a detail view which only needs one ``Poll`` object,
     213    but don't worry; ``Poll.objects.all()`` is actually a special
     214    object called a ``QuerySet``, which is "lazy" and doesn't hit your
     215    database until it absolutely has to. By the time the database
     216    query happens, the ``object_detail`` generic view will have
     217    narrowed its scope down to a single object, so the eventual query
     218    will only select one row from the database. If you'd like to know
     219    more about how that works, The Django database API documentation
     220    explains `the lazy nature of ``QuerySet`` objects`_.
     222.. _the lazy nature of ``QuerySet`` objects: ../db_api/#querysets-are-lazy
    209224In previous parts of the tutorial, the templates have been provided with a context
    210225that contains the ``poll`` and ``latest_poll_list`` context variables. However,
    211226the generic views provide the variables ``object`` and ``object_list`` as context.
Back to Top