mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #30902 -- Added __str__() for model choice enums.
Allows expected behavior when cast to str, also matching behaviour of created instances with those fetched from the DB. Thanks to Simon Charette, Nick Pope, and Shai Berger for reviews.
This commit is contained in:
parent
fc2b1cc926
commit
dbcd7b064e
2 changed files with 13 additions and 1 deletions
|
@ -143,6 +143,12 @@ class ChoicesTests(SimpleTestCase):
|
|||
APPLE = 1, 'Apple'
|
||||
PINEAPPLE = 1, 'Pineapple'
|
||||
|
||||
def test_str(self):
|
||||
for test in [Gender, Suit, YearInSchool, Vehicle]:
|
||||
for member in test:
|
||||
with self.subTest(member=member):
|
||||
self.assertEqual(str(test[member.name]), str(member.value))
|
||||
|
||||
|
||||
class Separator(bytes, models.Choices):
|
||||
FS = b'\x1c', 'File Separator'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue