Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#14120 closed (fixed)

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

Reported by: Daniel Roseman 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: no UI/UX: no

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 Daniel Roseman 14 years ago.
documentation patch
queryset-get.diff (2.9 KB ) - added by Adam Vandenberg 13 years ago.
Updated patch that removes trailing spaces and links the get.

Download all attachments as: .zip

Change History (5)

by Daniel Roseman, 14 years ago

Attachment: making_queries.diff added

documentation patch

comment:1 by Gabriel Hurley, 14 years ago

Triage Stage: UnreviewedAccepted

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

by Adam Vandenberg, 13 years ago

Attachment: queryset-get.diff added

Updated patch that removes trailing spaces and links the get.

comment:2 by Tim Graham, 13 years ago

Resolution: fixed
Status: newclosed

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

comment:3 by Tim Graham, 13 years ago

(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