From ae1ee24178ecd53ac5ef3fc2055e4be8b9602ac9 Mon Sep 17 00:00:00 2001 From: Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:40:21 +0200 Subject: Fixed #35766 -- Handled slices in BaseChoiceIterator. --- django/utils/choices.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'django/utils') 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)) -- cgit v1.3