From 51ebc8805e1a0bd5d347587f483fc07fc206df9f Mon Sep 17 00:00:00 2001 From: David Krisch Date: Thu, 7 May 2015 15:30:04 -1000 Subject: [1.8.x] Fixed #24763 -- Moved DoesNotExist exception to model docs. Backport of 1a62f197078eae72eba85f23aabacc06ad4c7d79 from master --- docs/ref/models/instances.txt | 19 ++++++++++++++++++- docs/ref/models/querysets.txt | 12 ++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) (limited to 'docs/ref/models') diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index c294704641..da567d29ec 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -826,7 +826,7 @@ For every :class:`~django.db.models.DateField` and `, 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 @@ -837,3 +837,20 @@ format described in :ref:`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() ` 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 e6e2335040..673037ec31 100644 --- a/docs/ref/models/querysets.txt +++ b/docs/ref/models/querysets.txt @@ -1578,15 +1578,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: @@ -1905,7 +1905,7 @@ If your model's :ref:`Meta ` 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 -- cgit v1.3