summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--django/db/models/query.py8
-rw-r--r--tests/regressiontests/queries/models.py2
2 files changed, 8 insertions, 2 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index b08f3acd14..5b9f504d2f 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -15,6 +15,9 @@ from django.utils.datastructures import SortedDict
CHUNK_SIZE = 100
ITER_CHUNK_SIZE = CHUNK_SIZE
+# The maximum number of items to display in a QuerySet.__repr__
+REPR_OUTPUT_SIZE = 20
+
# Pull into this namespace for backwards compatibility.
EmptyResultSet = sql.EmptyResultSet
@@ -141,7 +144,10 @@ class QuerySet(object):
return obj_dict
def __repr__(self):
- return repr(list(self))
+ data = list(self[:REPR_OUTPUT_SIZE + 1])
+ if len(data) > REPR_OUTPUT_SIZE:
+ data[-1] = "...(remaining elements truncated)..."
+ return repr(data)
def __len__(self):
# Since __len__ is called quite frequently (for example, as part of
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index e5d17c0aaf..12822c6f7a 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -556,7 +556,7 @@ Bug #2076
# automatically. Item normally requires a join with Note to do the default
# ordering, but that isn't needed here.
>>> qs = Item.objects.order_by('name')
->>> qs
+>>> list(qs)
[<Item: four>, <Item: one>, <Item: three>, <Item: two>]
>>> len(qs.query.tables)
1