mirror of https://github.com/django/django.git
Made QuerySet slicing return IndexError instead of DoesNotExist (and related changes).
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2859 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0727df90f0
commit
7a62bac56e
|
@ -264,7 +264,10 @@ class Model(object):
|
|||
q = self.__class__._default_manager.order_by((not is_next and '-' or '') + field.name, (not is_next and '-' or '') + self._meta.pk.name)
|
||||
q._where.append(where)
|
||||
q._params.extend([param, param, getattr(self, self._meta.pk.attname)])
|
||||
return q[0]
|
||||
try:
|
||||
return q[0]
|
||||
except IndexError, e:
|
||||
raise self.DoesNotExist, e.args
|
||||
|
||||
def _get_next_or_previous_in_order(self, is_next):
|
||||
cachename = "__%s_order_cache" % is_next
|
||||
|
|
|
@ -128,12 +128,12 @@ class QuerySet(object):
|
|||
else:
|
||||
return list(self._clone(_offset=offset, _limit=limit))[::k.step]
|
||||
else:
|
||||
return self._clone(_offset=k, _limit=1).get()
|
||||
try:
|
||||
return self._clone(_offset=k, _limit=1).get()
|
||||
except self.model.DoesNotExist, e:
|
||||
raise IndexError, e.args
|
||||
else:
|
||||
try:
|
||||
return self._result_cache[k]
|
||||
except IndexError:
|
||||
raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name
|
||||
return self._result_cache[k]
|
||||
|
||||
def __and__(self, other):
|
||||
combined = self._combine(other)
|
||||
|
|
|
@ -35,7 +35,7 @@ def shortcut(request, content_type_id, object_id):
|
|||
if field.rel.to is Site:
|
||||
try:
|
||||
object_domain = getattr(obj, field.name).all()[0].domain
|
||||
except Site.DoesNotExist:
|
||||
except IndexError:
|
||||
pass
|
||||
if object_domain is not None:
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue