summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDavid Sanders <shang.xiao.sanders@gmail.com>2022-10-02 00:42:10 +1000
committerGitHub <noreply@github.com>2022-10-01 16:42:10 +0200
commitda02cbd1effc951b14c981925d0e26a39566649e (patch)
tree6de938af99174e4b78aa028fa1a32c6f7ae4a0d8 /docs
parentbc3b8f152452ba0e41f28baa93c0bf8f39cddb09 (diff)
Clarified how to reference RelatedObjectDoesNotExist exceptions.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/fields.txt13
1 files changed, 7 insertions, 6 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 81a1422ddb..0afddc14a8 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -2012,13 +2012,14 @@ your resulting ``User`` model will have the following attributes::
A ``RelatedObjectDoesNotExist`` exception is raised when accessing the reverse
relationship if an entry in the related table doesn't exist. This is a subclass
of the target model's :exc:`Model.DoesNotExist
-<django.db.models.Model.DoesNotExist>` exception. For example, if a user
-doesn't have a supervisor designated by ``MySpecialUser``::
+<django.db.models.Model.DoesNotExist>` exception and can be accessed as an
+attribute of the reverse accessor. For example, if a user doesn't have a
+supervisor designated by ``MySpecialUser``::
- >>> user.supervisor_of
- Traceback (most recent call last):
- ...
- RelatedObjectDoesNotExist: User has no supervisor_of.
+ try:
+ user.supervisor_of
+ except User.supervisor_of.RelatedObjectDoesNotExist:
+ pass
.. _onetoone-arguments: