[Django] #33599: Enum is not usable in templates.

150 views
Skip to first unread message

Django

unread,
Mar 24, 2022, 8:49:54 AM3/24/22
to django-...@googlegroups.com
#33599: Enum is not usable in templates.
-----------------------------------------+--------------------------------
Reporter: davidmarogy | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.2
Severity: Normal | Keywords: Enum, Template
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+--------------------------------
Hello,

i tried using an normal Enum instead of a Textchoice in my Django-
Template. I created a therefore simple tag which gets an
enum(ModuleKind.SCHADENSANALYSE) and some other inputs. This resulted in
getting an empty string string instead of an Enum. Searching for a way to
solve this problem i stumbled upon
https://stackoverflow.com/questions/35953132/how-to-access-enum-types-in-
django-templates, which suggested a hack.

{{{
{% module_info_tiles user ModuleKind.SCHADENSANALYSE versdb_1_host
"servicebots/index.html?bot_id=1327" "Schadenanalyse" %}
}}}

Digging a little bit deeper, the same issue happend for enum types for
another ticket: https://code.djangoproject.com/ticket/31154

The solution would be the same as in the previous ticket, making the Enum
not callable in templates.

Best Regards
David

--
Ticket URL: <https://code.djangoproject.com/ticket/33599>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 24, 2022, 9:08:09 AM3/24/22
to django-...@googlegroups.com
#33599: Enum is not usable in templates.
--------------------------------+--------------------------------------
Reporter: David Marogy | Owner: nobody
Type: Bug | Status: closed
Component: Uncategorized | Version: 3.2
Severity: Normal | Resolution: wontfix

Keywords: Enum, Template | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => wontfix


Comment:

Unlike Django's choices enum subclasses that we were able to adjust in
#31154, Python's Enum type isn't something we can add attributes to in
Django.

The decorator suggestion on the SO thread seems like a way to go. (Equally
you can add the attribute by hand in e.g. `get_context_data`).

--
Ticket URL: <https://code.djangoproject.com/ticket/33599#comment:1>

Reply all
Reply to author
Forward
0 new messages