Opened 6 months ago

Closed 6 months ago

#33599 closed Bug (wontfix)

Enum is not usable in templates.

Reported by: David Marogy Owned by: nobody
Component: Uncategorized Version: 3.2
Severity: Normal Keywords: Enum, Template
Cc: david.marogy@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



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, 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:

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

Best Regards

Change History (1)

comment:1 Changed 6 months ago by Carlton Gibson

Resolution: wontfix
Status: newclosed

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).

Note: See TracTickets for help on using tickets.
Back to Top