Opened 16 years ago

Closed 16 years ago

#6639 closed (duplicate)

to_field is not followed in objects.get(fkmodel__fkattr=something) lookups

Reported by: dfrishberg <dfrishberg@…> Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When the to_field of a ForeignKey field is specified as something other than the primary key, FK lookups do not work properly in filtering. The to_field is ignored, because the django/db/models/ function follows a pk (as of revision 7138, this is at line 1031).

There's probably a better way to get the field name than I've got in this patch, and I imagine there may be more safety checking than I'm doing. But this fixed my problem.

Attachments (1)

query_patch.diff (1.1 KB ) - added by dfrishberg <dfrishberg@…> 16 years ago.

Download all attachments as: .zip

Change History (2)

by dfrishberg <dfrishberg@…>, 16 years ago

Attachment: query_patch.diff added

comment:1 by James Bennett, 16 years ago

Resolution: duplicate
Status: newclosed

Feels like a dupe of #4306, which is fixed in queryset-refactor. Please reopen if you can demonstrate that this is not the same issue.

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