summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuergen Schackmann <juergen.schackmann@gmail.com>2013-10-17 03:48:03 +0200
committerTim Graham <timograham@gmail.com>2013-10-18 16:22:47 -0400
commit8ffa99ccb6173e6dd53a83204933d99a9a6748a3 (patch)
treed0e2c859d81f19d95f250160f8b6d98cd60fd282
parent472917024b53ea4ff95fa103fcb76fa532f1ce66 (diff)
[1.5.x] Fixed #21212 -- Documented the reverse name for OneToOneField.
Thanks bjb at credil.org for the report. Backport of f8632572ad from master
-rw-r--r--docs/ref/models/fields.txt24
1 files changed, 24 insertions, 0 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 3ac0acf5f3..41c55075fe 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -1223,6 +1223,27 @@ related. This works exactly the same as it does for :class:`ForeignKey`,
including all the options regarding :ref:`recursive <recursive-relationships>`
and :ref:`lazy <lazy-relationships>` relationships.
+If you do not specify the the :attr:`~ForeignKey.related_name` argument for
+the ``OneToOneField``, Django will use the lower-case name of the current model
+as default value.
+
+With the following example::
+
+ from django.db import models
+ from django.contrib.auth.models import User
+
+ class MySpecialUser(models.Model):
+ user = models.OneToOneField(User)
+ supervisor = models.OneToOneField(User, related_name='supervisor_of')
+
+your resulting ``User`` model will have the following attributes::
+
+ >>> user = User.objects.get(pk=1)
+ >>> hasattr(user, 'myspecialuser')
+ True
+ >>> hasattr(user, 'supervisor_of')
+ True
+
.. _onetoone-arguments:
Additionally, ``OneToOneField`` accepts all of the extra arguments
@@ -1235,3 +1256,6 @@ accepted by :class:`ForeignKey`, plus one extra argument:
link back to the parent class, rather than the extra
``OneToOneField`` which would normally be implicitly created by
subclassing.
+
+See :doc:`One-to-one relationships </topics/db/examples/one_to_one>` for usage
+examples of ``OneToOneField``.