Opened 12 years ago
Closed 12 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?
Note:
See TracTickets
for help on using tickets.
Hi!
pkis just a shortcut, in your example it impliesid__exact, there's some docs about pk behavior here: https://docs.djangoproject.com/en/1.6/topics/db/queries/#the-pk-lookup-shortcut