Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #21212 -- Documented the reverse name for OneToOneField.

Thanks bjb at credil.org for the report.
  • Loading branch information...
commit f8632572ad84b05256423841cee6335490ba0698 1 parent a3372f6
authored October 17, 2013 timgraham committed October 18, 2013

Showing 1 changed file with 24 additions and 0 deletions. Show diff stats Hide diff stats

  1. 24  docs/ref/models/fields.txt
24  docs/ref/models/fields.txt
@@ -1325,6 +1325,27 @@ related. This works exactly the same as it does for :class:`ForeignKey`,
1325 1325
 including all the options regarding :ref:`recursive <recursive-relationships>`
1326 1326
 and :ref:`lazy <lazy-relationships>` relationships.
1327 1327
 
  1328
+If you do not specify the the :attr:`~ForeignKey.related_name` argument for
  1329
+the ``OneToOneField``, Django will use the lower-case name of the current model
  1330
+as default value.
  1331
+
  1332
+With the following example::
  1333
+
  1334
+    from django.db import models
  1335
+    from django.contrib.auth.models import User
  1336
+
  1337
+    class MySpecialUser(models.Model):
  1338
+        user = models.OneToOneField(User)
  1339
+        supervisor = models.OneToOneField(User, related_name='supervisor_of')
  1340
+
  1341
+your resulting ``User`` model will have the following attributes::
  1342
+
  1343
+    >>> user = User.objects.get(pk=1)
  1344
+    >>> hasattr(user, 'myspecialuser')
  1345
+    True
  1346
+    >>> hasattr(user, 'supervisor_of')
  1347
+    True
  1348
+
1328 1349
 .. _onetoone-arguments:
1329 1350
 
1330 1351
 Additionally, ``OneToOneField`` accepts all of the extra arguments
@@ -1337,3 +1358,6 @@ accepted by :class:`ForeignKey`, plus one extra argument:
1337 1358
     link back to the parent class, rather than the extra
1338 1359
     ``OneToOneField`` which would normally be implicitly created by
1339 1360
     subclassing.
  1361
+
  1362
+See :doc:`One-to-one relationships </topics/db/examples/one_to_one>` for usage
  1363
+examples of ``OneToOneField``.

0 notes on commit f863257

Please sign in to comment.
Something went wrong with that request. Please try again.