Code

Opened 7 years ago

Closed 7 years ago

#5585 closed (duplicate)

Default manager methods should allow _id style arguments for foreign keys

Reported by: Simon Litchfield <simon@…> Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Instead of being required to do this --

current_user = User.objects.get(id=47)
profile = Profile.objects.get(name='Example', user=current_user)

Since I can use profile.user_id, I would expect to be able to do this --

profile = Profile.objects.get(name='Example', user_id=47)

Both in terms of consistency *and* performance.

Another example gotcha, which obviously makes sense once you know it but needn't be the case if filters etc supported _id style arguments --

pa, created = ProfileAttrib.objects.get_or_create(profile=self.profile,
                                                  attrib__id=attrib_id,
                                                  value=value,
                                                  defaults={'attrib_id':attrib_id}
                                                  )

Why not, just --

pa, created = ProfileAttrib.objects.get_or_create(profile=self.profile,
                                                  attrib_id=attrib_id,
                                                  value=value,
                                                  )

Attachments (0)

Change History (1)

comment:1 Changed 7 years ago by ubernostrum

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

Duplicate of #5535.

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.