1
0
mirror of https://github.com/django/django.git synced 2025-07-05 18:29:11 +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:
Malcolm Tredinnick 2008-03-15 14:15:43 +00:00
parent 93baa3e417
commit ade818fd7d

View File

@ -173,14 +173,14 @@ class _QuerySet(object):
keyword arguments.
"""
clone = self.filter(*args, **kwargs)
obj_list = list(clone)
if len(obj_list) < 1:
num = len(clone)
if num == 1:
return clone._result_cache[0]
if not num:
raise self.model.DoesNotExist("%s matching query does not exist."
% 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"
% (self.model._meta.object_name, len(obj_list), kwargs))
return obj_list[0]
raise self.model.MultipleObjectsReturned("get() returned more than one %s -- it returned %s! Lookup parameters were %s"
% (self.model._meta.object_name, num, kwargs))
def create(self, **kwargs):
"""