Opened 7 years ago

Closed 7 years ago

#11719 closed (invalid)

Lookups that span relationships: Typo?

Reported by: bkjones@… Owned by: nobody
Component: Documentation Version: 1.1
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by ubernostrum)

I was reading here:

...and specifically this section:

This example retrieves all Entry objects with a Blog whose name is 'Beatles Blog':

>>> Entry.objects.filter(blog__name__exact='Beatles Blog')

This spanning can be as deep as you'd like.

It works backwards, too. To refer to a "reverse" relationship, just use the lowercase name of the model.

This example retrieves all Blog objects which have at least one Entry whose headline contains 'Lennon':

>>> Blog.objects.filter(entry__headline__contains='Lennon')

First, maybe I'm tired, but I don't see any difference in how the models in those two examples are different with respect to capitalization.

Second, the way it's written: "just use the lowercase name of the model" makes figuring out which example is correct and which might contain a typo ambiguous. That sentence should read something like "just use the lowercase name of the model in the argument to filter()". I do assume that that's what you're talking about, because the objects whose methods are being called are using Python lookups, no?

So, not a huge deal, it's a documentation bug (I think), but it could stump some newbies.

Change History (2)

comment:1 Changed 7 years ago by ubernostrum

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by ubernostrum

  • Resolution set to invalid
  • Status changed from new to closed

What it means is that Entry has an explicit field named blog, and so that's what you use for the lookup. Blog doesn't have an explicit field named entry, however -- the name to use in the lookup when traversing "backwards" is literally the name of the model -- Entry -- lowercased (to entry).

Note: See TracTickets for help on using tickets.
Back to Top