2

I'm trying to have special characters in field choices. I have the following code:

CHOICES = (('1', 'b'),
                ('2', 'p'),
                ('3', 'm'),
                ...
                ('11', 'ɾ'),
                ...)
field = models.CharField(choices=CHOICES, max_length=10, null=True, blank=True)

However when Django renders the select list for that field what I get is this:

<option value="11">&amp;#638;</option>

I tried manually printing the special characters and it works. But for some reason Django is converting the & to &amp;

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895

1 Answers1

2

Use a Python Unicode object as your label:

CHOICES = (('1', 'b'),
                ('2', 'p'),
                ('3', 'm'),
                ...
                ('11', u'\u027e'),
                ...)

Django will encode the character when rendering.

Peter DeGlopper
  • 36,326
  • 7
  • 90
  • 83