maraujop/django-crispy-forms — pull request #34 by danielnaab (2012-03-30 20:28:28+00:00)
Title: Use safe filter on choices used in {% for x in y %}

Pertaining to issue #33:

When an integer is used as a choice value with MultipleChoiceField, the CheckBoxSelectMultijple template has a unicode/string mismatch that prevents initial values from getting rendered.

This is due to Django behavior (either intended or otherwise), and this fix works around the problem by using the `safe` filter, which has the side-effect of coercing the value to unicode. This will not be a security threat as the value is not being rendered into the form, but is instead passed as an argument to a template tag.

For an illustration... in Python:

>>> '1' in ['1']
True
>>> '1' in [u'1']
True

The Django template tag `{% if choice.0 in field.value %}`, however, does not display the same symmetry.