#21212 closed Cleanup/optimization (fixed)
OneToOneField reference does not document the "reverse" name
Reported by: | Owned by: | schacki | |
---|---|---|---|
Component: | Documentation | Version: | dev |
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.
Change History (7)
comment:1 by , 11 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Version: | 1.5 → master |
comment:2 by , 11 years ago
#21216 is fixing an issue with hidden OneToOneField
reverse descriptor that should unify related_name
across all related fields.
comment:3 by , 11 years ago
Has patch: | set |
---|---|
Patch needs improvement: | set |
PR (needs some improvements).
comment:4 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
The reverse attribute is just
<othermodel>
(lowercased). We can also mention the name can be customized withrelated_name
(just likeForeignKey
).