mirror of
https://github.com/django/django.git
synced 2025-09-26 20:19:16 +00:00
Improved error message when index in __getitem__() is invalid.
This commit is contained in:
parent
8323691de0
commit
d89053585e
6 changed files with 28 additions and 4 deletions
|
@ -283,7 +283,10 @@ class QuerySet:
|
|||
def __getitem__(self, k):
|
||||
"""Retrieve an item or slice from the set of results."""
|
||||
if not isinstance(k, (int, slice)):
|
||||
raise TypeError
|
||||
raise TypeError(
|
||||
'QuerySet indices must be integers or slices, not %s.'
|
||||
% type(k).__name__
|
||||
)
|
||||
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))), \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue