Django

Code

Changeset 4637

Show
Ignore:
Timestamp:
02/26/07 22:27:47 (2 years ago)
Author:
jacob
Message:

Fixed #2565: added a note about the laziness of querysets in tutorial 4. Thanks, Ubernostrum.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/docs/tutorial04.txt

    r4420 r4637  
    207207template. Note that we use ``dict()`` to return an altered dictionary in place. 
    208208 
     209.. note:: ``all()`` is lazy 
     210 
     211    It might look a little frightening to see ``Poll.objects.all()`` being used 
     212    in a detail view which only needs one ``Poll`` object, but don't worry; 
     213    ``Poll.objects.all()`` is actually a special object called a ``QuerySet``, 
     214    which is "lazy" and doesn't hit your database until it absolutely has to. By 
     215    the time the database query happens, the ``object_detail`` generic view will 
     216    have narrowed its scope down to a single object, so the eventual query will 
     217    only select one row from the database.  
     218     
     219    If you'd like to know more about how that works, The Django database API 
     220    documentation `explains the lazy nature of QuerySet objects`_. 
     221 
     222.. _explains the lazy nature of QuerySet objects: ../db_api/#querysets-are-lazy 
     223 
    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,