Changeset 5831
- Timestamp:
- 08/08/07 16:09:55 (1 year ago)
- Files:
-
- django/trunk/django/db/models/query.py (modified) (1 diff)
- django/trunk/tests/modeltests/basic/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/db/models/query.py
r5768 r5831 115 115 def __getitem__(self, k): 116 116 "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)): 118 118 raise TypeError 119 119 assert (not isinstance(k, slice) and (k >= 0)) \ django/trunk/tests/modeltests/basic/models.py
r5803 r5831 248 248 [<Article: Area woman programs in Python>, <Article: Third article>] 249 249 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 250 263 # Slices (without step) are lazy: 251 264 >>> Article.objects.all()[0:5].filter()
