Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#14120 closed (fixed)

[patch] Document ``get()`` in Making Queries

Reported by: danielr Owned by: nobody
Component: Documentation Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

There's a frequent confusion among new users about the use of filter() when the query returns a single element - not realising that it will always return a QuerySet, they try and access model properties on the returned value, and get annoyed when they don't work. See for example here: http://stackoverflow.com/questions/3491075/comments-and-content-object, but similar queries come up all the time.

This is really a documentation issue, in that the main introductory page on Making Queries does not explain that filter() will always return a QuerySet, and neither does it explicitly document the get() alternative that is what the users in these cases probably should be using. get() is mentioned in passing on this page, and fully documented in the QuerySet API reference, but should be explained in full on this page, which is the first page users will go to.

Attached patch adds a "Retrieving a single object with get" section after the filter() documentation.

Attachments (2)

making_queries.diff (2.4 KB) - added by danielr 5 years ago.
documentation patch
queryset-get.diff (2.9 KB) - added by adamv 4 years ago.
Updated patch that removes trailing spaces and links the get.

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by danielr

documentation patch

comment:1 Changed 5 years ago by gabrielhurley

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Also worth noting that there's an unlinked "See get() for more details" on line 307 that should be linked up in this patch.

Changed 4 years ago by adamv

Updated patch that removes trailing spaces and links the get.

comment:2 Changed 4 years ago by timo

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

(In [14820]) Fixed #14120 - Document get() in Making Queries - thanks danielr and adamv for work on the patch.

comment:3 Changed 4 years ago by timo

(In [14821]) [1.2.X] Fixed #14120 - Document get() in Making Queries - thanks danielr and adamv for work on the patch.

Backport of r14820 from trunk.

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