Django

Code

Changeset 5831

Show
Ignore:
Timestamp:
08/08/07 16:09:55 (1 year ago)
Author:
gwilson
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/query.py

    r5768 r5831  
    115115    def __getitem__(self, k): 
    116116        "Retrieve an item or slice from the set of results." 
    117         if not isinstance(k, (slice, int)): 
     117        if not isinstance(k, (slice, int, long)): 
    118118            raise TypeError 
    119119        assert (not isinstance(k, slice) and (k >= 0)) \ 
  • django/trunk/tests/modeltests/basic/models.py

    r5803 r5831  
    248248[<Article: Area woman programs in Python>, <Article: Third article>] 
    249249 
     250# Slicing works with longs. 
     251>>> Article.objects.all()[0L] 
     252<Article: Area woman programs in Python> 
     253>>> Article.objects.all()[1L:3L] 
     254[<Article: Second article>, <Article: Third article>] 
     255>>> s3 = Article.objects.filter(id__exact=3) 
     256>>> (s1 | s2 | s3)[::2L] 
     257[<Article: Area woman programs in Python>, <Article: Third article>] 
     258 
     259# And can be mixed with ints. 
     260>>> Article.objects.all()[1:3L] 
     261[<Article: Second article>, <Article: Third article>] 
     262 
    250263# Slices (without step) are lazy: 
    251264>>> Article.objects.all()[0:5].filter()