Opened 5 years ago
Last modified 5 years ago
#31154 closed Bug
Enumeration Types not usable in templates — at Initial Version
Reported by: | Adam Johnson | Owned by: | nobody |
---|---|---|---|
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
The new [enumeration types](https://docs.djangoproject.com/en/3.0/ref/models/fields/#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.