Code

Opened 8 months ago

Closed 7 months 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?

Attachments (0)

Change History (1)

comment:1 Changed 7 months ago by polmuz

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

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.