Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#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)

Screenshot from 2016-08-19 23:18:18.png (101.3 KB ) - added by Abhishek Bera 8 years ago.
asnote_1.png (101.3 KB ) - added by Abhishek Bera 8 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 by Tim Graham, 8 years ago

Summary: doc: .get() without args is worth mentioningDocument using .get() without args to return an object from a single-row queryset
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

comment:2 by Abhishek Bera, 8 years ago

Owner: changed from nobody to Abhishek Bera
Status: newassigned

comment:3 by Abhishek Bera, 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.

Doesn't this point imply the same??

comment:4 by Abhishek Bera, 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())
Last edited 8 years ago by Tim Graham (previous) (diff)

by Abhishek Bera, 8 years ago

by Abhishek Bera, 8 years ago

Attachment: asnote_1.png added

comment:5 by Tim Graham, 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.

Version 0, edited 8 years ago by Tim Graham (next)

comment:6 by Abhishek Bera, 8 years ago

Update: suggest edits
That's how it looks now


in reply to:  5 comment:7 by Abhishek Bera, 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 Abhishek Bera, 8 years ago

Has patch: set
Patch needs improvement: set

comment:9 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In f3b601f1:

Fixed #26987 -- Documented using QuerySet.get() without arguments.

comment:10 by Tim Graham <timograham@…>, 8 years ago

In a77d979:

[1.10.x] Fixed #26987 -- Documented using QuerySet.get() without arguments.

Backport of f3b601f11a7b56777ac1173a390787d176f95fe3 from master

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