[2.0.x] Fixed #29081 -- Clarified comments in QuerySet.select_related() example.

Backport of e6f0e324e2 from master
This commit is contained in:
Tim Graham 2018-01-29 10:12:58 -05:00
parent c2962d8147
commit bbc4a5a792
1 changed files with 3 additions and 1 deletions

View File

@ -941,11 +941,13 @@ following models::
... then a call to ``Book.objects.select_related('author__hometown').get(id=4)``
will cache the related ``Person`` *and* the related ``City``::
# Hits the database with joins to the author and hometown tables.
b = Book.objects.select_related('author__hometown').get(id=4)
p = b.author # Doesn't hit the database.
c = p.hometown # Doesn't hit the database.
b = Book.objects.get(id=4) # No select_related() in this example.
# Without select_related()...
b = Book.objects.get(id=4) # Hits the database.
p = b.author # Hits the database.
c = p.hometown # Hits the database.