Fixed #8065 -- Made id_list an optional argument for QuerySet.in_bulk().

This commit is contained in:
Bryan Marty 2015-10-29 23:24:46 -07:00 committed by Tim Graham
parent 2a7ce34600
commit 62ca2dea04
4 changed files with 32 additions and 8 deletions

View file

@ -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):