Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #5115 -- Fixed `QuerySet` slices to allow longs.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5831 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 049212e95079d612b37b6fb9f3fba8616f5f7a7b 1 parent 9170744
Gary Wilson Jr. gdub authored
Showing with 14 additions and 1 deletion.
  1. +1 −1  django/db/models/query.py
  2. +13 −0 tests/modeltests/basic/models.py
2  django/db/models/query.py
View
@@ -114,7 +114,7 @@ def __iter__(self):
def __getitem__(self, k):
"Retrieve an item or slice from the set of results."
- if not isinstance(k, (slice, int)):
+ if not isinstance(k, (slice, int, long)):
raise TypeError
assert (not isinstance(k, slice) and (k >= 0)) \
or (isinstance(k, slice) and (k.start is None or k.start >= 0) and (k.stop is None or k.stop >= 0)), \
13 tests/modeltests/basic/models.py
View
@@ -247,6 +247,19 @@ def __unicode__(self):
>>> (s1 | s2 | s3)[::2]
[<Article: Area woman programs in Python>, <Article: Third article>]
+# Slicing works with longs.
+>>> Article.objects.all()[0L]
+<Article: Area woman programs in Python>
+>>> Article.objects.all()[1L:3L]
+[<Article: Second article>, <Article: Third article>]
+>>> s3 = Article.objects.filter(id__exact=3)
+>>> (s1 | s2 | s3)[::2L]
+[<Article: Area woman programs in Python>, <Article: Third article>]
+
+# And can be mixed with ints.
+>>> Article.objects.all()[1:3L]
+[<Article: Second article>, <Article: Third article>]
+
# Slices (without step) are lazy:
>>> Article.objects.all()[0:5].filter()
[<Article: Area woman programs in Python>, <Article: Second article>, <Article: Third article>, <Article: Article 6>, <Article: Default headline>]
Please sign in to comment.
Something went wrong with that request. Please try again.