Search code examples
pythondjangotastypie

Django + Tastypie + support utf8


I trying to create a new django app with tastypie api support.

I have created a model:

class Lead(models.Model): 

    BERUFSSTATUS = (
        ("Rentner/-in", "Rentner/-in"),
        ("Schüler/-in", "Schüler/-in"),
    )

    employmentstatus = models.CharField(max_length=50, blank=False, choices=BERUFSSTATUS)

The problem is, I trying to insert

"employmentstatus":"Schüler/-in"

I get this error:

 "Value u'Sch\\xfcler/-in' is not in list."

How to fix this?


Solution

  • Include the following at the beginning of the file -

    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    

    This would set default encoding to Unicode.