#26987 closed Cleanup/optimization (fixed)
Document using .get() without args to return an object from a single-row queryset
Reported by: | Vlada Macek | Owned by: | Abhishek Bera |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | yes | UI/UX: | no |
Description
The doc
https://docs.djangoproject.com/en/1.10/ref/models/querysets/#get
could IMO mention that queryset.get()
returns a row from a single-row queryset. Feature becomes handy sometimes.
Attachments (2)
Change History (12)
comment:1 by , 8 years ago
Summary: | doc: .get() without args is worth mentioning → Document using .get() without args to return an object from a single-row queryset |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 8 years ago
comment:4 by , 8 years ago
``get()`` raises :exc:`~django.core.exceptions.MultipleObjectsReturned` if more than one object was found. The :exc:`~django.core.exceptions.MultipleObjectsReturned` exception is an attribute of the model class. .. Note:: In case of no parameters, column of single-row queryset is returned. for example: if Entry.objects.all().count() == 1: print(Entry.objects.get())
by , 8 years ago
Attachment: | Screenshot from 2016-08-19 23:18:18.png added |
---|
by , 8 years ago
Attachment: | asnote_1.png added |
---|
follow-up: 7 comment:5 by , 8 years ago
What you've written is a starting point for discussion -- can you send a pull request? We don't need screenshots of the documentation.
Starting point of discussion?? Can you please tell me what that means?
Extremely sorry.. I joined today
comment:7 by , 8 years ago
Replying to timgraham:
What you've written is a starting point for discussion -- can you send a pull request? We don't need screenshots of the documentation.
Starting point of discussion?? Can you please tell me what that means?
Extremely sorry.. I joined today.
P.S. I made the pull request from berabhishek:ticket_26987
comment:8 by , 8 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
get()
raises :exc:
~django.core.exceptions.MultipleObjectsReturned
if morethan one object was found. The
:exc:
~django.core.exceptions.MultipleObjectsReturned
exception is anattribute of the model class.
Doesn't this point imply the same??