Was Form choice.choice_value silently removed in 1.11?

182 views
Skip to first unread message

Rodney Folz

unread,
Apr 4, 2017, 7:33:18 PM4/4/17
to Django users
Hi all, congrats on the 1.11 release!

Prior to Django 1.11's form template rendering, I had a form template that rendered choices like so:

```
    {% for choice in form.field_with_choices %} # forms.ChoiceField()
        {% if choice.choice_value is Value %}
```

Not the prettiest, but it's worked for now. When upgrading from 1.10 to 1.11, our tests around these templates broke. I couldn't find anything in the 1.11 release/upgrade notes about this, so I did a bit of digging.

The reason seems to be that the new form rendering uses the django.forms.boundfield.BoundWidget class, which doesn't have a choice_value attribute/method. It does have choice_label() and other related methods, just not choice_value(). Previous widget rendering exposed choice.choice_value to the template, not choice._choice_value, so this seems to be a regression.

Was the removal of choice.choice_value() on purpose? If so, would you be open to a PR for the release notes indicating that it was removed in favor of using `choice.data.value`?

Best,
Rodney

Tim Graham

unread,
Apr 4, 2017, 10:45:43 PM4/4/17
to Django users
It looks like that's covered here:

https://docs.djangoproject.com/en/1.11/releases/1.11/#changes-due-to-the-introduction-of-template-based-widget-rendering

choice_value is an attribute of ChoiceInput which was undocumented and removed.

Rodney Folz

unread,
Apr 7, 2017, 5:39:12 PM4/7/17
to Django users
Ah, you're right. I must have missed that. Thanks very much!
Reply all
Reply to author
Forward
0 new messages