Code

Opened 7 months ago

Closed 6 months ago

Last modified 6 months ago

#21212 closed Cleanup/optimization (fixed)

OneToOneField reference does not document the "reverse" name

Reported by: bjb@… Owned by: schacki
Component: Documentation Version: master
Severity: Normal Keywords: OneToOneField, reverse
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: yes UI/UX: no

Description

https://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield

Says OneToOneField is like ForeignKey, and does not name the reverse attribute.

ForeignKey states that the reverse attribute is called <othermodel>_set and can refer to multiple models. The OneToOneField documentation says the reverse attribute returns a single object, but doesn't say what the reverse name is (surely not <othermodel>_set? - but if not that, then what?)

This is true for 1.5 and dev documentation - probably true for other versions as well.

It would also be nice it if explicitly stated that an instance of the other model can exist without having an instance of the model that refers to it with OneToOneField. Eg, if you have:

Place

Restaurant

place = OneToOneField (Place)

Then you can have a place record without a Restaurant record, but you cannot have a Restaurant record without a Place record. This is alluded to in the Place/Restaurant example elsewhere https://docs.djangoproject.com/en/dev/topics/db/examples/one_to_one/, but could be stated in the OneToOneField documentation.

This may be related to #10227. But until any change are implemented, I'm for documenting the actual behaviour.

Attachments (0)

Change History (7)

comment:1 Changed 7 months ago by timo

  • Easy pickings set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version changed from 1.5 to master

The reverse attribute is just <othermodel> (lowercased). We can also mention the name can be customized with related_name (just like ForeignKey).

comment:2 Changed 7 months ago by charettes

#21216 is fixing an issue with hidden OneToOneField reverse descriptor that should unify related_name across all related fields.

comment:3 Changed 6 months ago by timo

  • Has patch set
  • Patch needs improvement set

PR (needs some improvements).

comment:4 Changed 6 months ago by schacki

  • Owner changed from nobody to schacki
  • Status changed from new to assigned

comment:5 Changed 6 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In f8632572ad84b05256423841cee6335490ba0698:

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

Thanks bjb at credil.org for the report.

comment:6 Changed 6 months ago by Tim Graham <timograham@…>

In f198abc7e4f0ac4b2d7e1aa6e860ffb2e491810a:

[1.6.x] Fixed #21212 -- Documented the reverse name for OneToOneField.

Thanks bjb at credil.org for the report.

Backport of f8632572ad from master

comment:7 Changed 6 months ago by Tim Graham <timograham@…>

In 8ffa99ccb6173e6dd53a83204933d99a9a6748a3:

[1.5.x] Fixed #21212 -- Documented the reverse name for OneToOneField.

Thanks bjb at credil.org for the report.

Backport of f8632572ad from master

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.