Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#5582 closed (worksforme)

Default manager and model init methods should allow raw field name arguments for foreign keys

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

Description

I can do this --

profile = Profile(name='Example')
profile.user_id = 47
profile.save()

But not this --

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

Also can't get_or_create, or do anything much with only user_id directly. Apparently I need to instantiate a User object just for the sake of it(?) Turns out either a big overhead (50+ extra queries on this particular page!) -or- a bunch of unnecessary code.

More importantly though, it seems at least a bit confusing and inconsistent, that I can access it by attribute but not by argument.

Surely it would be easy enough to allow fieldname_id as init/filter arguments on foreign keys. If anyone else agrees, I'll run up the patch?

Change History (3)

comment:1 Changed 8 years ago by Simon Litchfield <simon@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 8 years ago by ubernostrum

  • Resolution set to worksforme
  • Status changed from new to closed

Passing the "_id"-style argument directly into the model constructor works for me on current trunk. Similarly, it works in create, and it works in the defaults argument to get_or_create.

comment:3 Changed 8 years ago by Simon Litchfield <simon@…>

Sorry, correction, see #5585

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