mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #32460 -- Allowed "label"/"do_not_call_in_templates" members in model choice enums.
This commit is contained in:
committed by
Mariusz Felisiak
parent
41e39c41c9
commit
a96c730431
@@ -159,6 +159,26 @@ class ChoicesTests(SimpleTestCase):
|
||||
with self.assertRaises(AttributeError):
|
||||
models.TextChoices('Properties', 'choices labels names values')
|
||||
|
||||
def test_label_member(self):
|
||||
# label can be used as a member.
|
||||
Stationery = models.TextChoices('Stationery', 'label stamp sticker')
|
||||
self.assertEqual(Stationery.label.label, 'Label')
|
||||
self.assertEqual(Stationery.label.value, 'label')
|
||||
self.assertEqual(Stationery.label.name, 'label')
|
||||
|
||||
def test_do_not_call_in_templates_member(self):
|
||||
# do_not_call_in_templates is not implicitly treated as a member.
|
||||
Special = models.IntegerChoices('Special', 'do_not_call_in_templates')
|
||||
self.assertEqual(
|
||||
Special.do_not_call_in_templates.label,
|
||||
'Do Not Call In Templates',
|
||||
)
|
||||
self.assertEqual(Special.do_not_call_in_templates.value, 1)
|
||||
self.assertEqual(
|
||||
Special.do_not_call_in_templates.name,
|
||||
'do_not_call_in_templates',
|
||||
)
|
||||
|
||||
|
||||
class Separator(bytes, models.Choices):
|
||||
FS = b'\x1c', 'File Separator'
|
||||
|
||||
Reference in New Issue
Block a user