[Django] #22048: Document ways of checking for OneToOneField

24 views
Skip to first unread message

Django

unread,
Feb 14, 2014, 11:38:34 PM2/14/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
-------------------------------------+-------------------------------------
Reporter: EvilDMP | Owner: nobody
Type: | Status: new
Uncategorized | Version: master
Component: | Keywords: afraid-to-commit
Documentation | Has patch: 0
Severity: Normal | Needs tests: 0
Triage Stage: | Easy pickings: 1
Unreviewed |
Needs documentation: 0 |
Patch needs improvement: 0 |
UI/UX: 0 |
-------------------------------------+-------------------------------------
https://docs.djangoproject.com/en/dev/topics/db/examples/one_to_one/#one-
to-one-relationships points out that if you try to follow the
`related_name` of a OneToOneField to something that doesn't exist, you'll
get a `DoesNotExist` error.

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.

Django

unread,
Feb 18, 2014, 7:59:25 AM2/18/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:1>

Django

unread,
Feb 22, 2014, 10:27:30 AM2/22/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: assigned

Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by code22):

* owner: nobody => code22
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:2>

Django

unread,
Feb 22, 2014, 2:36:47 PM2/22/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Feb 23, 2014, 5:55:22 AM2/23/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by code22):

i've made some improvements to my pull request

--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:4>

Django

unread,
Feb 23, 2014, 6:37:39 AM2/23/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by code22):

another improvement ready for checking

--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:5>

Django

unread,
Mar 18, 2014, 8:46:56 AM3/18/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timo):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/22048#comment:6>

Django

unread,
Mar 24, 2014, 9:45:52 AM3/24/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed

Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Mar 24, 2014, 9:46:15 AM3/24/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Django

unread,
Mar 24, 2014, 9:46:16 AM3/24/14
to django-...@googlegroups.com
#22048: Document ways of checking for OneToOneField
--------------------------------------+------------------------------------
Reporter: EvilDMP | Owner: code22
Type: Cleanup/optimization | Status: closed
Component: Documentation | Version: master
Severity: Normal | Resolution: fixed
Keywords: afraid-to-commit | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages