diff --git a/django/core/paginator.py b/django/core/paginator.py
index 9ccff51..e366176 100644
|
a
|
b
|
|
| 1 | 1 | import collections |
| 2 | 2 | from math import ceil |
| 3 | 3 | |
| | 4 | from django.db.models.query import QuerySet |
| 4 | 5 | from django.utils import six |
| 5 | 6 | |
| 6 | 7 | |
| … |
… |
class Page(collections.Sequence):
|
| 121 | 122 | raise TypeError |
| 122 | 123 | # The object_list is converted to a list so that if it was a QuerySet |
| 123 | 124 | # it won't be a database hit per __getitem__. |
| 124 | | return list(self.object_list)[index] |
| | 125 | if isinstance(self.object_list, QuerySet): |
| | 126 | self.object_list = list(self.object_list) |
| | 127 | return self.object_list[index] |
| 125 | 128 | |
| 126 | 129 | def has_next(self): |
| 127 | 130 | return self.number < self.paginator.num_pages |
diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py
index dea5756..2e71ee5 100644
|
a
|
b
|
from __future__ import absolute_import, unicode_literals
|
| 2 | 2 | |
| 3 | 3 | from datetime import datetime |
| 4 | 4 | |
| | 5 | from django.db.models.query import QuerySet |
| 5 | 6 | from django.core.paginator import (Paginator, EmptyPage, InvalidPage, |
| 6 | 7 | PageNotAnInteger) |
| 7 | 8 | from django.test import TestCase |
| … |
… |
class ModelPaginationTests(TestCase):
|
| 305 | 306 | "<Article: Article 2>", |
| 306 | 307 | ] |
| 307 | 308 | ) |
| | 309 | |
| | 310 | def test_pagination_list_conv(self): |
| | 311 | # Make sure paginator created from queryset is evaluated to list |
| | 312 | paginator = Paginator(Article.objects.all(), 5) |
| | 313 | p = paginator.page(1) |
| | 314 | self.assertTrue(isinstance(p.object_list, QuerySet)) |
| | 315 | p[1] |
| | 316 | self.assertTrue(isinstance(p.object_list, list)) |
| | 317 | |
| | 318 | # Make sure that non-list data is not evaluated to list |
| | 319 | paginator = Paginator((1, 2, 3), 5) |
| | 320 | p = paginator.page(1) |
| | 321 | self.assertTrue(isinstance(p.object_list, tuple)) |
| | 322 | p[1] |
| | 323 | self.assertTrue(isinstance(p.object_list, tuple)) |