Opened 14 years ago

Closed 13 years ago

#16048 closed Bug (fixed)

GenericForeignKey always uses a default manager of a related model

Reported by: Ivan Virabyan Owned by: nobody
Component: contrib.contenttypes Version: 1.3
Severity: Normal Keywords: genericforeignkey manager
Cc: me@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

From Django docs:
By default, Django uses an instance of a "plain" manager class when accessing related objects (i.e. choice.poll), not the default manager on the related object. This is because Django needs to be able to retrieve the related object, even if it would otherwise be filtered out (and hence be inaccessible) by the default manager.

This is true for ForeignKey, but not GenericForeignKey. So I have no ability to use custom managers for my models, because they are being filtered when I'm accessing related objects.

Attachments (1)

ticket16048-r16259.diff (2.4 KB ) - added by Andy Durdin 13 years ago.
Patch against trunk revision 16259

Download all attachments as: .zip

Change History (8)

comment:1 by Andy Durdin, 13 years ago

Owner: changed from nobody to Andy Durdin
Status: newassigned

by Andy Durdin, 13 years ago

Attachment: ticket16048-r16259.diff added

Patch against trunk revision 16259

comment:2 by Andy Durdin, 13 years ago

Has patch: set
Owner: changed from Andy Durdin to nobody
Status: assignednew
Triage Stage: UnreviewedAccepted

A straightforward bug both to test and fix. Patch with tests and fix attached.

comment:3 by Andy Durdin, 13 years ago

Cc: Andy Durdin added

comment:4 by Dougal Matthews, 13 years ago

Triage Stage: AcceptedReady for checkin

Looks good.

comment:5 by Andy Durdin, 13 years ago

Cc: Andy Durdin removed

comment:6 by Andy Durdin, 13 years ago

Cc: me@… added

comment:7 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16261]:

Fixed #16048 -- Use the base manager instead of the default manager to retrieve a related object of a GenericForeignKey similar to ForeignKeys. Thanks, adurdin.

Note: See TracTickets for help on using tickets.
Back to Top