mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #31154 -- Added support for using enumeration types in templates.
Enumeration helpers are callables, so the template system tried to call them with no arguments. Thanks Rupert Baker for helping discover this.
This commit is contained in:
committed by
Mariusz Felisiak
parent
4c1b401e82
commit
5166097d7c
@@ -4,6 +4,7 @@ import ipaddress
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.template import Context, Template
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.functional import Promise
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@@ -149,6 +150,11 @@ class ChoicesTests(SimpleTestCase):
|
||||
with self.subTest(member=member):
|
||||
self.assertEqual(str(test[member.name]), str(member.value))
|
||||
|
||||
def test_templates(self):
|
||||
template = Template('{{ Suit.DIAMOND.label }}|{{ Suit.DIAMOND.value }}')
|
||||
output = template.render(Context({'Suit': Suit}))
|
||||
self.assertEqual(output, 'Diamond|1')
|
||||
|
||||
|
||||
class Separator(bytes, models.Choices):
|
||||
FS = b'\x1c', 'File Separator'
|
||||
|
||||
Reference in New Issue
Block a user