Use `TextField` instead of `PositiveIntegerField` in docs and examples for generic relations.
|Reported by:||Tai Lee||Owned by:||Gabriel Hurley|
|Severity:||Keywords:||generic relation genericforeignkey object_id type textfield sprintdec2010|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The docs state that the
object_id field on a generic model that is linked back to with
GenericForeignKey fields must be the same type, usually
PositiveIntegerField. This is not entirely true since  which coerces the primary key value to the same type as the
object_id field on the generic model.
This means that
TextField should be the preferred type for
object_id fields on generic models, because it will allow models with integer and non-integer (anything that can be coerced to a string) to link back to the generic model in question.
Django actually uses
TextField (I presume, for this reason) for its own internal generic models (
BaseCommentAbstractModel), so it makes sense that we should tell users how to avoid this old limitation and set a best practice by example.
Change History (22)
comment:8 Changed 6 years ago by
|Patch needs improvement:||set|
|Triage Stage:||Unreviewed → Accepted|
comment:18 Changed 6 years ago by
|Owner:||set to Gabriel Hurley|
|Status:||new → closed|