#27511 closed Bug (fixed)
Docs incorrect about related_model for GenericRelation being None
Reported by: | Amir Keivan Mohtashami | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 1.10 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
The documentation says for field.related_model:
If a field has a generic relation (such as a GenericForeignKey or a GenericRelation) then related_model will be None.
However this is not true for GenericRelations. For these fields the related_model points to the model the field relates to just like the reverse of a ForeignKey. The documentation should be fixed, however this means that to the best of my knowledge, there is no way to distinguish between GenericRelation and reverse of a ForeignKey(short of checking if the field is an instance of GenericRelation).
Attachments (1)
Change History (9)
comment:1 by , 8 years ago
Component: | Uncategorized → Documentation |
---|---|
Has patch: | set |
Summary: | related_model for GenericRelation is not None → Docs incorrect about related_model for GenericRelation being None |
Triage Stage: | Unreviewed → Accepted |
by , 8 years ago
Attachment: | 27511.diff added |
---|
comment:2 by , 8 years ago
Since GenericRelation is actually a generic field, isn't it better to explicitly exclude it from the rule?
comment:3 by , 8 years ago
In the patch, I meant to write, "If a field is a GenericForeignKey". (chop extra "generic")
I'm not sure if your comment is suggesting a documentation change or a code change?
comment:4 by , 8 years ago
The change you propose will correctly describe the current behavior of Django.
However I don't know whether it is the right approach to change the documentation or would it be better to update the code. Since related_model is set to None for GenericForeignKey it might be reasonable to set it to None for GenericRelation as well.
comment:5 by , 8 years ago
Since related_model is set to None for GenericForeignKey it might be reasonable to set it to None for GenericRelation as well.
GenericForeignKey.related_model
is set to None
as it can point to many models by the generic nature of the foreign key. GenericRelation
always point to a single reverse model so I believe things should be kept this way.
comment:6 by , 8 years ago
I see. Then I guess after removing the additional "generic" the proposed patch should be enough.
Is the attached patch fine?