diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-17 10:32:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-17 10:32:43 +0200 |
| commit | 82da72b74851808c08ec98fe609efe52609f29ad (patch) | |
| tree | 9f2125907b0984960feaaebfe214dd20b250d2cf | |
| parent | 1621f06051c94665f2edf492c10316875896e7eb (diff) | |
Refs #28077 -- Added opclasses to Index.__repr__().
This also removes unnecessary commas between attributes.
| -rw-r--r-- | django/db/models/indexes.py | 7 | ||||
| -rw-r--r-- | tests/model_indexes/tests.py | 14 |
2 files changed, 16 insertions, 5 deletions
diff --git a/django/db/models/indexes.py b/django/db/models/indexes.py index 0662006404..f0f6cdab15 100644 --- a/django/db/models/indexes.py +++ b/django/db/models/indexes.py @@ -123,10 +123,11 @@ class Index: self.name = 'D%s' % self.name[1:] def __repr__(self): - return "<%s: fields='%s'%s%s>" % ( + return "<%s: fields='%s'%s%s%s>" % ( self.__class__.__name__, ', '.join(self.fields), - '' if self.condition is None else ', condition=%s' % self.condition, - '' if not self.include else ", include='%s'" % ', '.join(self.include), + '' if self.condition is None else ' condition=%s' % self.condition, + '' if not self.include else " include='%s'" % ', '.join(self.include), + '' if not self.opclasses else " opclasses='%s'" % ', '.join(self.opclasses), ) def __eq__(self, other): diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py index ff3c6c73c7..93ac47130a 100644 --- a/tests/model_indexes/tests.py +++ b/tests/model_indexes/tests.py @@ -22,12 +22,22 @@ class SimpleIndexesTests(SimpleTestCase): name='include_idx', include=['author', 'pages'], ) + opclasses_index = models.Index( + fields=['headline', 'body'], + name='opclasses_idx', + opclasses=['varchar_pattern_ops', 'text_pattern_ops'], + ) self.assertEqual(repr(index), "<Index: fields='title'>") self.assertEqual(repr(multi_col_index), "<Index: fields='title, author'>") - self.assertEqual(repr(partial_index), "<Index: fields='title', condition=(AND: ('pages__gt', 400))>") + self.assertEqual(repr(partial_index), "<Index: fields='title' condition=(AND: ('pages__gt', 400))>") self.assertEqual( repr(covering_index), - "<Index: fields='title', include='author, pages'>", + "<Index: fields='title' include='author, pages'>", + ) + self.assertEqual( + repr(opclasses_index), + "<Index: fields='headline, body' " + "opclasses='varchar_pattern_ops, text_pattern_ops'>", ) def test_eq(self): |
