Django + sqlite + Unicode

django, python, unicode

Solution

I found a solution. Actually, the problem was not in Django or sqlite. The issue was with the unicode() method.

Previously it was:

def __unicode__(self):
    return "{} ({})".format(self.translation, self.word.lang.abbr)

After an obvious fix, the problem is gone:

def __unicode__(self):
    return u"{} ({})".format(self.translation, self.word.lang.abbr)

Problem

I faced a problem with Unicode strings while adding new records to a sqlite database through the admin site. ``` class Translation(BaseModel): ..... translation = models.CharField(max_length=100) ``` When I try to insert a word like 'été' an error occurs: ``` **UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)** ``` Update: Added traceback: http://pastebin.com/yLYFNDGB

Original source

Related problems