[Fixed]-Django-tastypie: utf8 is incorrect

1👍

Instead of __str__() use __unicode__(). And use smart_text:

from django.utils.encoding import smart_text

class ActionName(models.Model):
    name = models.CharField(max_length=300) 
    def __unicode__(self):
        return smart_text(self.name)

BTW: Instead of dehydrate() use fields:

from tastypie import fields

class ActionResource(ModelResource):
    name = fields.CharField('name__name', null=True)

    class Meta:
        queryset = ActionInfo.objects.all()
        resource_name = 'action'

BTW2:

>>> print u'Солянка'.encode('windows-1251')
Солянка
>>> print u'Солянка'.encode('windows-1251').decode('utf8')
Солянка

Leave a comment