#11864 closed (fixed)
Relationship backreference documentation is hard to find
Reported by: | anonymous | Owned by: | Derek Willis |
---|---|---|---|
Component: | Documentation | Version: | 1.1 |
Severity: | Keywords: | relationships foreigkey | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I would expect that documentation on backreferences in relationships would be documented under Model API documentation, but it takes a few clicks from there to see how it works.
http://docs.djangoproject.com/en/dev/topics/db/models/#relationships
will, if the seeker of wisdom is pretty sharp or diligent, lead to one link labeled "the model field reference", which if followed, takes one to
http://docs.djangoproject.com/en/dev/ref/models/fields/#foreign-key-arguments
From there, one follows a link labeled "related objects documentation" that points at
http://docs.djangoproject.com/en/dev/topics/db/queries/#backwards-related-objects
which is where the fact that if I have a one-many relationship between Foo and Bar, where the Bar model class has a ForeignKey reference to Foo, then instances of the Foo
class will have an attribute named "bar_set" whose value is a relationship manager (and that fact's documented on a page about queries).
All this means that the highly useful and important fact about how Django manages the relationship from Foos to Bars is two clicks and quite a bit of reading away from the starting point from learning about
relationships. It might be useful for newcomers to have a quicker path (perhaps including a sentence example of the form "if a Car model has a ForeignKey reference to the Manufacturer model, then Manufacturer instances will have an attribute "car_set" that provides access to the related Car instances") -- a natural place for this example might be under the docs for ForeignKey.related_name (http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.related_name), but as it's such a useful an interesting feature, if there's an even more prominent place to put it, so much the better.
thanks!
Attachments (2)
Change History (15)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 15 years ago
milestone: | 1.2 |
---|
comment:4 by , 14 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
by , 14 years ago
Attachment: | 11864.diff added |
---|
comment:5 by , 14 years ago
Has patch: | set |
---|
comment:6 by , 14 years ago
Added a patch with an example of the backwards relationship in topics/db/models, with a link to the fuller example.
comment:7 by , 14 years ago
Patch needs improvement: | set |
---|
I don't think that belongs there at all. It goes straight from providing the syntax for ForeignKey to talking about following backwards relationships - it hasn't even shown how to follow forwards ones yet. I think this would be better off with a simple link from there to the Related objects documentation (topics/db/queries/#related-objects), perhaps replacing the existing See Also box which unhelpfully goes to the FK doctests.
comment:8 by , 14 years ago
milestone: | → 1.3 |
---|
comment:9 by , 14 years ago
The solution here is fairly simple, in line with danielr's suggestion.
The whole ending of the Many-to-One Relationships section should be cleaned up as follows:
- The "see also" section should become the last item in that section.
- The text under the "see also" about the model field reference is also a "see also" and should be in the "see also" box.
- The new information (the subject of this ticket) is *yet another* "see also" and should be in that box as well.
There should be no problem presenting the three distinctly within that callout.
We don't need to provide separate information about backwards relationships in this document, only make it easier to arrive at the existing information.
by , 14 years ago
Attachment: | 11864-revised.diff added |
---|
comment:10 by , 14 years ago
Patch needs improvement: | unset |
---|
Added revised patch using gabrielhurley's recommendations.
comment:11 by , 14 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
In [15758]:
(The changeset message doesn't reference this ticket)
This isn't critical to 1.2; we can always go back and improve documentation as needed, but attention right now should focus on actual bugs.