Opened 7 years ago

Closed 7 years ago

#11938 closed (duplicate)

`to_field` does not function as expected.

Reported by: David Cramer Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: to_field
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In lookups involving a ForeignKey, or a ManyToMany intermediary table using a to_field they fail due to looking for the primary key, rather than the field specified by to_field.

For example:

    user = models.ForeignKey(User, to_field="username")
    # Fails
    SimpleModel.objects.get(user=self.user)

Attachments (2)

to_field_tests.py (1.0 KB) - added by David Cramer 7 years ago.
to_field_tests.2.py (1.4 KB) - added by David Cramer 7 years ago.
Additional test case on deletion.

Download all attachments as: .zip

Change History (3)

Changed 7 years ago by David Cramer

Attachment: to_field_tests.py added

Changed 7 years ago by David Cramer

Attachment: to_field_tests.2.py added

Additional test case on deletion.

comment:1 Changed 7 years ago by Russell Keith-Magee

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

This is a dupe of #11319, which is itself an amalgam of #10243 and #10785.

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