From 755bb2a3f2c7e59f2b7cb7daacb65acad79c7e19 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Fri, 8 Feb 2008 04:21:39 +0000 Subject: [PATCH] queryset-refactor: Added (back) in support for using strings in slices. Apparently there exists code that like to do this, including the admin interface. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7094 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/query.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/django/db/models/query.py b/django/db/models/query.py index 193624144d..1a3a0b55ec 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -78,7 +78,11 @@ class _QuerySet(object): # The result cache has only been partially populated, so we may # need to fill it out a bit more. if isinstance(k, slice): - bound = k.stop + if k.stop is not None: + # Some people insist on passing in strings here. + bound = int(k.stop) + else: + bound = None else: bound = k + 1 if len(self._result_cache) < bound: @@ -87,7 +91,15 @@ class _QuerySet(object): if isinstance(k, slice): qs = self._clone() - qs.query.set_limits(k.start, k.stop) + if k.start is not None: + start = int(k.start) + else: + start = None + if k.stop is not None: + stop = int(k.stop) + else: + stop = None + qs.query.set_limits(start, stop) return k.step and list(qs)[::k.step] or qs try: qs = self._clone()