Opened 4 years ago

Closed 4 years ago

Last modified 4 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 4 years ago.
asnote_1.png (101.3 KB) - added by Abhishek Bera 4 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 4 years ago by Tim Graham

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 Changed 4 years ago by Abhishek Bera

Owner: changed from nobody to Abhishek Bera
Status: newassigned

comment:3 Changed 4 years ago by Abhishek Bera

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 Changed 4 years ago by Abhishek Bera

``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 4 years ago by Tim Graham (previous) (diff)

Changed 4 years ago by Abhishek Bera

Changed 4 years ago by Abhishek Bera

Attachment: asnote_1.png added

comment:5 Changed 4 years ago by Tim Graham

What you've written is a starting point for discussion -- can you send a pull request? We don't need screenshots of the documentation.

Last edited 4 years ago by Abhishek Bera (previous) (diff)

comment:6 Changed 4 years ago by Abhishek Bera

Update: suggest edits
That's how it looks now


comment:7 in reply to:  5 Changed 4 years ago by Abhishek Bera

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 Changed 4 years ago by Abhishek Bera

Has patch: set
Patch needs improvement: set

comment:9 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In f3b601f1:

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

comment:10 Changed 4 years ago by Tim Graham <timograham@…>

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