Opened 4 years ago

Last modified 4 years ago

#31154 closed Bug

Enumeration Types are not usable in templates. — at Version 2

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 (2)

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
Note: See TracTickets for help on using tickets.
Back to Top