Opened 5 years ago

Closed 5 years ago

#20994 closed Uncategorized (invalid)

Referencing a ForeignKey raw value doesn't follow convention

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


When we want to look up a ForeignKey via a filter, but don't know the name of the Primary Key field, we use Model.objects.filter(pk=lookup_value)

But when we're getting the raw value of a ForeignKey, we use model_instance.foreignkey_id

Surely it should be foreignkey_pk in line with the filter?

Change History (1)

comment:1 Changed 5 years ago by polmuz

Resolution: invalid
Status: newclosed


pk is just a shortcut, in your example it implies id__exact, there's some docs about pk behavior here:

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