#31154: Enumeration Types are not usable in templates. -------------------------------------+------------------------------------- Reporter: Adam (Chainz) | Owner: Adam Johnson | (Chainz) Johnson Type: Bug | Status: assigned Component: Database layer | Version: 3.0 (models, ORM) | Severity: Release blocker | Resolution: Keywords: | Triage Stage: Accepted Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Changes (by felixxm):
* severity: Normal => Release blocker * component: Template system => Database layer (models, ORM) * has_patch: 0 => 1 * stage: Unreviewed => Accepted Old 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. New description: The new [https://docs.djangoproject.com/en/3.0/ref/models/fields /#enumeration-types 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. -- Comment: [https://github.com/django/django/pull/12304 PR] -- Ticket URL: <https://code.djangoproject.com/ticket/31154#comment:2> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/068.0b0e02ddab48454fce8dd10d8e9b8328%40djangoproject.com.