summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-15 14:15:43 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-15 14:15:43 +0000
commitade818fd7db2be2d3cb2d6e26b6cc1e06dae6865 (patch)
tree04f41b27483f4127b7ba94f2f02f00e9ef2dc5eb
parent93baa3e4170ea40be967d48560ffca55395be07b (diff)
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
-rw-r--r--django/db/models/query.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 3d2e6cea1e..5a82988e3d 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -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):
"""