Opened 15 years ago

Closed 14 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: no UI/UX: no

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 15 years ago.
to_field_tests.2.py (1.4 KB ) - added by David Cramer 15 years ago.
Additional test case on deletion.

Download all attachments as: .zip

Change History (3)

by David Cramer, 15 years ago

Attachment: to_field_tests.py added

by David Cramer, 15 years ago

Attachment: to_field_tests.2.py added

Additional test case on deletion.

comment:1 by Russell Keith-Magee, 14 years ago

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