diff options
author | Adam Johnson <me@adamj.eu> | 2020-01-09 15:41:54 +0000 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-01-10 09:13:36 +0100 |
commit | 16297e7d5e3a6b0287d114e95d1d544995618c93 (patch) | |
tree | c29a80f82ec0ff8e6afd7e701cc1319646bff518 /tests | |
parent | 2efc832cdfa7eec5905b11dbf0b6855aa0f6447d (diff) | |
download | django-16297e7d5e3a6b0287d114e95d1d544995618c93.tar.gz |
[3.0.x] 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.
Backport of 5166097d7c80cab757e44f2d02f3d148fbbc2ff6 from master
Diffstat (limited to 'tests')
-rw-r--r-- | tests/model_enums/tests.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tests/model_enums/tests.py b/tests/model_enums/tests.py index e1810e673a..1136114807 100644 --- a/tests/model_enums/tests.py +++ b/tests/model_enums/tests.py @@ -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' |