What's missing is advice on how to check if there's a related object.
The most obvious is `hasattr`. Using the Restaurant/Place example in
https://docs.djangoproject.com/en/dev/topics/db/examples/one_to_one/#one-
to-one-relationships: `hasattr(place, 'restaurant')`.
I've also seen https://djangosnippets.org/snippets/2254/ (uses
`ObjectDoesNotExist`) and even things like
http://stackoverflow.com/a/14743656/2422705 (uses `select_related`).
It should also be explained a little more why a missing object returns a
`DoesNotExist`, rather than say `None`.
--
Ticket URL: <https://code.djangoproject.com/ticket/22048>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:1>
* owner: nobody => code22
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:2>
Comment (by code22):
pull request for this ticket: https://github.com/django/django/pull/2356
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:3>
Comment (by code22):
i've made some improvements to my pull request
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:4>
Comment (by code22):
another improvement ready for checking
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:6>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"ec08d62a20f55cfdfb9fbd21d8bc5627c54337c7"]:
{{{
#!CommitTicketReference repository=""
revision="ec08d62a20f55cfdfb9fbd21d8bc5627c54337c7"
Fixed #22048 - Enhanced docs to cover nonexistent one-to-one
relationships.
Thanks EvilDMP for the suggestion.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"eb1600e9d1916d9db40ce1dce101224bd8859add"]:
{{{
#!CommitTicketReference repository=""
revision="eb1600e9d1916d9db40ce1dce101224bd8859add"
[1.7.x] Fixed #22048 - Enhanced docs to cover nonexistent one-to-one
relationships.
Thanks EvilDMP for the suggestion.
Backport of ec08d62a20 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"38096da5c0db7e7a3bb5b6e977f8e17adbf389ac"]:
{{{
#!CommitTicketReference repository=""
revision="38096da5c0db7e7a3bb5b6e977f8e17adbf389ac"
[1.6.x] Fixed #22048 - Enhanced docs to cover nonexistent one-to-one
relationships.
Thanks EvilDMP for the suggestion.
Backport of ec08d62a20 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:9>