summaryrefslogtreecommitdiff
path: root/docs/ref/models
diff options
context:
space:
mode:
authorDavid Krisch <david@hq.realgeeks.com>2015-05-07 15:30:04 -1000
committerTim Graham <timograham@gmail.com>2015-05-08 13:05:50 -0400
commit1a62f197078eae72eba85f23aabacc06ad4c7d79 (patch)
tree9669173b0e15fcc555ffdc951357bc804bc44f73 /docs/ref/models
parent681df1aeafb30092430157f7977f713e1ce234ca (diff)
Fixed #24763 -- Moved DoesNotExist exception to model docs.
Diffstat (limited to 'docs/ref/models')
-rw-r--r--docs/ref/models/instances.txt19
-rw-r--r--docs/ref/models/querysets.txt12
2 files changed, 24 insertions, 7 deletions
diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt
index 162384c3c7..02903668d1 100644
--- a/docs/ref/models/instances.txt
+++ b/docs/ref/models/instances.txt
@@ -824,7 +824,7 @@ For every :class:`~django.db.models.DateField` and
<django.db.models.Field.null>`, the object will have ``get_next_by_FOO()`` and
``get_previous_by_FOO()`` methods, where ``FOO`` is the name of the field. This
returns the next and previous object with respect to the date field, raising
-a :exc:`~django.core.exceptions.DoesNotExist` exception when appropriate.
+a :exc:`~django.db.models.Model.DoesNotExist` exception when appropriate.
Both of these methods will perform their queries using the default
manager for the model. If you need to emulate filtering used by a
@@ -835,3 +835,20 @@ format described in :ref:`Field lookups <field-lookups>`.
Note that in the case of identical date values, these methods will use the
primary key as a tie-breaker. This guarantees that no records are skipped or
duplicated. That also means you cannot use those methods on unsaved objects.
+
+Other attributes
+================
+
+``DoesNotExist``
+----------------
+
+.. exception:: Model.DoesNotExist
+
+ This exception is raised by the ORM in a couple places, for example by
+ :meth:`QuerySet.get() <django.db.models.query.QuerySet.get>` when an object
+ is not found for the given query parameters.
+
+ Django provides a ``DoesNotExist`` exception as an attribute of each model
+ class to identify the class of object that could not be found and to allow
+ you to catch a particular model class with ``try/except``. The exception is
+ a subclass of :exc:`django.core.exceptions.ObjectDoesNotExist`.
diff --git a/docs/ref/models/querysets.txt b/docs/ref/models/querysets.txt
index d2cbc63203..510fbcbbb8 100644
--- a/docs/ref/models/querysets.txt
+++ b/docs/ref/models/querysets.txt
@@ -1543,15 +1543,15 @@ than one object was found. The
:exc:`~django.core.exceptions.MultipleObjectsReturned` exception is an
attribute of the model class.
-``get()`` raises a :exc:`~django.core.exceptions.DoesNotExist` exception if an
-object wasn't found for the given parameters. This exception is also an
-attribute of the model class. Example::
+``get()`` raises a :exc:`~django.db.models.Model.DoesNotExist` exception if an
+object wasn't found for the given parameters. This exception is an attribute
+of the model class. Example::
Entry.objects.get(id='foo') # raises Entry.DoesNotExist
-The :exc:`~django.core.exceptions.DoesNotExist` exception inherits from
+The :exc:`~django.db.models.Model.DoesNotExist` exception inherits from
:exc:`django.core.exceptions.ObjectDoesNotExist`, so you can target multiple
-:exc:`~django.core.exceptions.DoesNotExist` exceptions. Example::
+:exc:`~django.db.models.Model.DoesNotExist` exceptions. Example::
from django.core.exceptions import ObjectDoesNotExist
try:
@@ -1868,7 +1868,7 @@ If your model's :ref:`Meta <meta-options>` specifies
field specified in :attr:`~django.db.models.Options.get_latest_by` by default.
Like :meth:`get()`, ``earliest()`` and ``latest()`` raise
-:exc:`~django.core.exceptions.DoesNotExist` if there is no object with the
+:exc:`~django.db.models.Model.DoesNotExist` if there is no object with the
given parameters.
Note that ``earliest()`` and ``latest()`` exist purely for convenience and