From da02cbd1effc951b14c981925d0e26a39566649e Mon Sep 17 00:00:00 2001 From: David Sanders Date: Sun, 2 Oct 2022 00:42:10 +1000 Subject: [PATCH] Clarified how to reference RelatedObjectDoesNotExist exceptions. --- docs/ref/models/fields.txt | 13 +++++++------ 1 file 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 -` exception. For example, if a user -doesn't have a supervisor designated by ``MySpecialUser``:: +` 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: