mirror of
https://github.com/django/django.git
synced 2025-07-06 02:39:12 +00:00
queryset-refactor: Sped up QuerySet.get() by using fast paths through the iterator maze.
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7248 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
93baa3e417
commit
ade818fd7d
@ -173,14 +173,14 @@ class _QuerySet(object):
|
|||||||
keyword arguments.
|
keyword arguments.
|
||||||
"""
|
"""
|
||||||
clone = self.filter(*args, **kwargs)
|
clone = self.filter(*args, **kwargs)
|
||||||
obj_list = list(clone)
|
num = len(clone)
|
||||||
if len(obj_list) < 1:
|
if num == 1:
|
||||||
|
return clone._result_cache[0]
|
||||||
|
if not num:
|
||||||
raise self.model.DoesNotExist("%s matching query does not exist."
|
raise self.model.DoesNotExist("%s matching query does not exist."
|
||||||
% self.model._meta.object_name)
|
% self.model._meta.object_name)
|
||||||
elif len(obj_list) > 1:
|
raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s"
|
||||||
raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s"
|
% (self.model._meta.object_name, num, kwargs))
|
||||||
% (self.model._meta.object_name, len(obj_list), kwargs))
|
|
||||||
return obj_list[0]
|
|
||||||
|
|
||||||
def create(self, **kwargs):
|
def create(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user