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 = 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._where.append(where)
|
||||||
q._params.extend([param, param, getattr(self, self._meta.pk.attname)])
|
q._params.extend([param, param, getattr(self, self._meta.pk.attname)])
|
||||||
|
try:
|
||||||
return q[0]
|
return q[0]
|
||||||
|
except IndexError, e:
|
||||||
|
raise self.DoesNotExist, e.args
|
||||||
|
|
||||||
def _get_next_or_previous_in_order(self, is_next):
|
def _get_next_or_previous_in_order(self, is_next):
|
||||||
cachename = "__%s_order_cache" % is_next
|
cachename = "__%s_order_cache" % is_next
|
||||||
|
|
|
@ -127,13 +127,13 @@ class QuerySet(object):
|
||||||
return self._clone(_offset=offset, _limit=limit)
|
return self._clone(_offset=offset, _limit=limit)
|
||||||
else:
|
else:
|
||||||
return list(self._clone(_offset=offset, _limit=limit))[::k.step]
|
return list(self._clone(_offset=offset, _limit=limit))[::k.step]
|
||||||
else:
|
|
||||||
return self._clone(_offset=k, _limit=1).get()
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
return self._clone(_offset=k, _limit=1).get()
|
||||||
|
except self.model.DoesNotExist, e:
|
||||||
|
raise IndexError, e.args
|
||||||
|
else:
|
||||||
return self._result_cache[k]
|
return self._result_cache[k]
|
||||||
except IndexError:
|
|
||||||
raise self.model.DoesNotExist, "%s matching query does not exist." % self.model._meta.object_name
|
|
||||||
|
|
||||||
def __and__(self, other):
|
def __and__(self, other):
|
||||||
combined = self._combine(other)
|
combined = self._combine(other)
|
||||||
|
|
|
@ -35,7 +35,7 @@ def shortcut(request, content_type_id, object_id):
|
||||||
if field.rel.to is Site:
|
if field.rel.to is Site:
|
||||||
try:
|
try:
|
||||||
object_domain = getattr(obj, field.name).all()[0].domain
|
object_domain = getattr(obj, field.name).all()[0].domain
|
||||||
except Site.DoesNotExist:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
if object_domain is not None:
|
if object_domain is not None:
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue