Opened 7 years ago

Closed 7 years ago

#27970 closed New feature (fixed)

Allow in_bulk() to use other unique fields besides the primary key

Reported by: Tom Carrick Owned by: Tom Carrick
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Currently in_bulk() has a very limited set of use-cases, especially since a lot of Django users prefer to keep the ID as the PK even when another field could be used. It could be expanded to be more useful if it could be used on fields other than the ID.

For backwards compatibility, it should only work on unique fields.

Proposed syntax: Foo.objects.in_bulk(['1', '2', 'AB123'], field='account_number')

Change History (6)

comment:1 by Tim Graham, 7 years ago

Summary: Allow in_bulk() to use other fieldsAllow in_bulk() to use other unique fields besides the primary key
Triage Stage: UnreviewedAccepted

Seems okay at first glance.

comment:2 by Tom Carrick, 7 years ago

Owner: changed from nobody to Tom Carrick
Status: newassigned

Going to have a quick stab at this.

comment:3 by Tom Carrick, 7 years ago

Has patch: set
Needs documentation: set

PR (without documentation)

Last edited 7 years ago by Tim Graham (previous) (diff)

comment:4 by Tom Carrick, 7 years ago

Needs documentation: unset

Forgot to update the ticket, docs are in now, just needs review.

comment:5 by Tom Carrick, 7 years ago

Triage Stage: AcceptedReady for checkin

comment:6 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 3159ad4d:

Fixed #27970 -- Allowed QuerySet.in_bulk() to fetch on fields besides primary key.

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