mirror of
https://github.com/django/django.git
synced 2025-08-02 10:02:41 +00:00
[2.2.x] Fixed #30931 -- Restored ability to override Model.get_FIELD_display().
Thanks Sergey Fedoseev for the implementation idea. Regression ina68ea23101
. Backport of2d38eb0ab9
from master
This commit is contained in:
parent
eb8a53c7c1
commit
785d1706c4
3 changed files with 19 additions and 2 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue