Opened 11 years ago

Closed 11 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

Description

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 by polmuz, 11 years ago

Resolution: invalid
Status: newclosed

Hi!

pk is just a shortcut, in your example it implies id__exact, there's some docs about pk behavior here: https://docs.djangoproject.com/en/1.6/topics/db/queries/#the-pk-lookup-shortcut

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