diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-10-31 11:34:56 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-11-04 08:17:50 +0100 |
| commit | 785d1706c411168d5acfa709157f60399ea690d0 (patch) | |
| tree | f9e687cba43b63e30283669fe6ce39ad8ba044e7 /tests | |
| parent | eb8a53c7c1c445cc8245bf0b2136d3062e6c7d17 (diff) | |
[2.2.x] Fixed #30931 -- Restored ability to override Model.get_FIELD_display().
Thanks Sergey Fedoseev for the implementation idea.
Regression in a68ea231012434b522ce45c513d84add516afa60.
Backport of 2d38eb0ab9f78d68c083a5b78b1eca39027b279a from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_fields/tests.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/model_fields/tests.py b/tests/model_fields/tests.py index 9e38f0fcf0..7a26fe01e5 100644 --- a/tests/model_fields/tests.py +++ b/tests/model_fields/tests.py @@ -114,6 +114,16 @@ class ChoicesTests(SimpleTestCase): self.assertIsNone(Whiz(c=None).get_c_display()) # Blank value self.assertEqual(Whiz(c='').get_c_display(), '') # Empty value + def test_overriding_FIELD_display(self): + class FooBar(models.Model): + foo_bar = models.IntegerField(choices=[(1, 'foo'), (2, 'bar')]) + + def get_foo_bar_display(self): + return 'something' + + f = FooBar(foo_bar=1) + self.assertEqual(f.get_foo_bar_display(), 'something') + def test_iterator_choices(self): """ get_choices() works with Iterators. |
