#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)
Change History (5)
by , 14 years ago
Attachment: | making_queries.diff added |
---|
comment:1 by , 14 years ago
Triage Stage: | Unreviewed → 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.
by , 14 years ago
Attachment: | queryset-get.diff added |
---|
Updated patch that removes trailing spaces and links the get.
comment:2 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
documentation patch