Opened 10 months ago

Closed 9 months ago

Last modified 9 months ago

#31154 closed Bug (fixed)

Enumeration Types are not usable in templates.

Reported by: Adam (Chainz) Johnson Owned by: Adam (Chainz) Johnson
Component: Database layer (models, ORM) Version: 3.0
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Mariusz Felisiak)

The new enumeration types are great but can't be used in Django templates due to their being callable. For example this doesn't work:

{% if student.year_in_school == YearInSchool.FRESHMAN %}

This is because YearInSchool, being a class, is callable, and Django Templates always call callables with no arguments. The call fails because the required value argument is missing.

The easy solution would be to declare do_not_call_in_templates = True on the various Choices classes.

Change History (4)

comment:1 Changed 10 months ago by Adam (Chainz) Johnson

Owner: changed from nobody to Adam (Chainz) Johnson
Status: newassigned

comment:2 Changed 10 months ago by Mariusz Felisiak

Component: Template systemDatabase layer (models, ORM)
Description: modified (diff)
Has patch: set
Severity: NormalRelease blocker
Summary: Enumeration Types not usable in templatesEnumeration Types are not usable in templates.
Triage Stage: UnreviewedAccepted

comment:3 Changed 9 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 5166097:

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.

comment:4 Changed 9 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In 16297e7:

[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

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