mirror of
https://github.com/django/django.git
synced 2025-09-23 02:33:31 +00:00
Fixed #8065 -- Made id_list an optional argument for QuerySet.in_bulk().
This commit is contained in:
parent
2a7ce34600
commit
62ca2dea04
4 changed files with 32 additions and 8 deletions
|
@ -559,16 +559,19 @@ class QuerySet(object):
|
|||
return objects[0]
|
||||
return None
|
||||
|
||||
def in_bulk(self, id_list):
|
||||
def in_bulk(self, id_list=None):
|
||||
"""
|
||||
Returns a dictionary mapping each of the given IDs to the object with
|
||||
that ID.
|
||||
that ID. If `id_list` isn't provided, the entire QuerySet is evaluated.
|
||||
"""
|
||||
assert self.query.can_filter(), \
|
||||
"Cannot use 'limit' or 'offset' with in_bulk"
|
||||
if not id_list:
|
||||
return {}
|
||||
qs = self.filter(pk__in=id_list).order_by()
|
||||
if id_list is not None:
|
||||
if not id_list:
|
||||
return {}
|
||||
qs = self.filter(pk__in=id_list).order_by()
|
||||
else:
|
||||
qs = self._clone()
|
||||
return {obj._get_pk_val(): obj for obj in qs}
|
||||
|
||||
def delete(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue