{{{
{% 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/31154>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Adam (Chainz) Johnson
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31154#comment:1>
* 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>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5166097d7c80cab757e44f2d02f3d148fbbc2ff6" 5166097]:
{{{
#!CommitTicketReference repository=""
revision="5166097d7c80cab757e44f2d02f3d148fbbc2ff6"
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.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31154#comment:3>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"16297e7d5e3a6b0287d114e95d1d544995618c93" 16297e7]:
{{{
#!CommitTicketReference repository=""
revision="16297e7d5e3a6b0287d114e95d1d544995618c93"
[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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31154#comment:4>