Fixed #24858 -- Added support for get_FOO_display() to ArrayField and RangeFields.

_get_FIELD_display() crashed when Field.choices was unhashable.
This commit is contained in:
Hasan Ramezani 2019-11-07 15:35:33 +01:00 committed by Mariusz Felisiak
parent 8058d9d7ad
commit 153c7956f8
5 changed files with 84 additions and 1 deletions

View file

@ -7,6 +7,7 @@ from django.core import exceptions, serializers
from django.db.models import DateField, DateTimeField, F, Func, Value
from django.http import QueryDict
from django.test import override_settings
from django.test.utils import isolate_apps
from django.utils import timezone
from . import PostgreSQLSimpleTestCase, PostgreSQLTestCase
@ -22,6 +23,30 @@ except ImportError:
pass
@isolate_apps('postgres_tests')
class BasicTests(PostgreSQLSimpleTestCase):
def test_get_field_display(self):
class Model(PostgreSQLModel):
field = pg_fields.IntegerRangeField(
choices=[
['1-50', [((1, 25), '1-25'), ([26, 50], '26-50')]],
((51, 100), '51-100'),
],
)
tests = (
((1, 25), '1-25'),
([26, 50], '26-50'),
((51, 100), '51-100'),
((1, 2), '(1, 2)'),
([1, 2], '[1, 2]'),
)
for value, display in tests:
with self.subTest(value=value, display=display):
instance = Model(field=value)
self.assertEqual(instance.get_field_display(), display)
class TestSaveLoad(PostgreSQLTestCase):
def test_all_fields(self):