Opened 13 months ago
Closed 13 months ago
#35224 closed Cleanup/optimization (fixed)
Make GenericForeignKey a subclass of Field
Description (last modified by ) ¶
When introduced in bca5327b21eb2e3ee18292cbe532d6d0071201d8, GenericForeignKey was created as its own class. Since then, it has grown to resemble a field, particularly in fb48eb05816b1ac87d58696cdfe48be18c901f16.
GenericForeignKey *not* being a Field
leads to several issues:
- It is added as a “field” and returned by
Model._meta.get_fields()
, a type confusion reflected in django-stubs. - It duplicates code, such as
_check_field_name()
. - It misses methods like
__repr__()
.
I think we should make it a subclass of Field
.
(GenericRelation
has always been a subclass of Field
.)
Change History (10)
comment:1 by , 13 months ago
Description: | modified (diff) |
---|
comment:2 by , 13 months ago
Description: | modified (diff) |
---|---|
Summary: | Make GenericForeignKey subclass Field → Make GenericForeignKey a subclass of Field |
comment:3 by , 13 months ago
Has patch: | set |
---|
comment:4 by , 13 months ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:5 by , 13 months ago
Owner: | changed from | to
---|
comment:7 by , 13 months ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:8 by , 13 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
Dylan, I already attached a PR to this ticket.
comment:9 by , 13 months ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
I'm eager to see what the test suite says but it seems like a worth cleanup!