#23732: select_related() documentation examples use incorrect fieldnames, and 
are
slightly misleading
-------------------------------+--------------------
     Reporter:  EvilDMP        |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  Documentation  |    Version:  master
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  1              |      UI/UX:  0
-------------------------------+--------------------
 
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.select_related
 says that if you have the models

 {{{
 class City(models.Model):
     # ...
     pass

 class Person(models.Model):
     # ...
     hometown = models.ForeignKey(City)

 class Book(models.Model):
     # ...
     author = models.ForeignKey(Person)
 }}}

 then you can do a `Book.objects.select_related('person__city').get(id=4)
 `.

 But in fact that, and the other examples that follow, should be using
 `select_related('author__hometown')` (the names of the fields, rather than
 of the models they refer to).

 These examples should be changed.

 A related issue in the same section: the examples might lead one to
 believe that `select_related` works only when retrieving a single item
 with `get()` (unlike `prefetch_related`, whose examples involve retrieving
 multiple objects), whereas this is not in fact the case.

 An example using `filter()` or some more explicit wording in the
 description (or both) would help here.

--
Ticket URL: <https://code.djangoproject.com/ticket/23732>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.5d7aee817634c58dc123fccfe9d71ad2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to