Skip to content

Commit

Permalink
[4.1.x] Clarified how to reference RelatedObjectDoesNotExist exceptions.
Browse files Browse the repository at this point in the history
Backport of da02cbd from main
  • Loading branch information
shangxiao authored and felixxm committed Oct 1, 2022
1 parent 96c541e commit f783148
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions docs/ref/models/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit f783148

Please sign in to comment.