1
0
mirror of https://github.com/django/django.git synced 2025-10-26 15:16:09 +00:00

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

Backport of f3b601f11a from master
This commit is contained in:
Abhishek Bera
2016-08-19 23:51:33 +05:30
committed by Tim Graham
parent 33783a9e06
commit a77d979cbd

View File

@@ -1624,6 +1624,11 @@ The :exc:`~django.db.models.Model.DoesNotExist` exception inherits from
except ObjectDoesNotExist: except ObjectDoesNotExist:
print("Either the entry or blog doesn't exist.") print("Either the entry or blog doesn't exist.")
If you expect a queryset to return one row, you can use ``get()`` without any
arguments to return the object for that row::
entry = Entry.objects.filter(...).exclude(...).get()
``create()`` ``create()``
~~~~~~~~~~~~ ~~~~~~~~~~~~