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
  • 567,968
  • 59
  • 825
  • 842

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
  • 34,778
  • 7
  • 86
  • 81