[patch] Document ``get()`` in Making Queries
|Reported by:||danielr||Owned by:||nobody|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.
Change History (5)
Changed 4 years ago by danielr
comment:1 Changed 3 years ago by gabrielhurley
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted