diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-09-17 12:40:21 +0200 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-09-18 16:45:53 +0200 |
| commit | ae1ee24178ecd53ac5ef3fc2055e4be8b9602ac9 (patch) | |
| tree | 1412f68d1d4999797e56ad394ccbb92c266b893c /django/utils | |
| parent | 9ca1f6eff6f19d1ae074d289c6c4209073351805 (diff) | |
Fixed #35766 -- Handled slices in BaseChoiceIterator.
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/choices.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/django/utils/choices.py b/django/utils/choices.py index 7f40bce510..6b355d2324 100644 --- a/django/utils/choices.py +++ b/django/utils/choices.py @@ -21,8 +21,9 @@ class BaseChoiceIterator: return super().__eq__(other) def __getitem__(self, index): - if index < 0: - # Suboptimally consume whole iterator to handle negative index. + if isinstance(index, slice) or index < 0: + # Suboptimally consume whole iterator to handle slices and negative + # indexes. return list(self)[index] try: return next(islice(self, index, index + 1)) |
