Opened 6 years ago

Closed 5 years ago

#11938 closed (duplicate)

`to_field` does not function as expected.

Reported by: dcramer 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 dcramer 6 years ago.
to_field_tests.2.py (1.4 KB) - added by dcramer 6 years ago.
Additional test case on deletion.

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by dcramer

Changed 6 years ago by dcramer

Additional test case on deletion.

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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