Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31154 closed Bug (fixed)

Enumeration Types are not usable in templates.

Reported by: Adam Johnson Owned by: Adam 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 by Adam Johnson, 4 years ago

Owner: changed from nobody to Adam Johnson
Status: newassigned

comment:2 by Mariusz Felisiak, 4 years ago

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 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

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 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

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