Django-tastypie: utf8 is incorrect
<pre><code>class ActionResource(ModelResource):

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

    def dehydrate(self, bundle):
        bundle.data['name'] = bundle.obj.name
        bundle.data['expect_time'] = bundle.obj.expect_time
        bundle.data['type'] = bundle.obj.type
        bundle.data['price'] = bundle.obj.price
        bundle.data['additional'] = bundle.obj.additional
        return bundle
</code></pre>

<p>This code from resource.py. Charfields that have russian letters print incorrect, for example: name: "Ð ÐÐ ÑÐ Â»Ð¡ÐÐ ÐÐ ÑÐ Â°". I've added at the top of the resource.py:</p>

<pre><code># -*- coding: UTF-8 -*-
from __future__ import unicode_literals
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
</code></pre>

<p>and return string from django models: </p>

<pre><code>class ActionName(models.Model):
    name = models.CharField(max_length=300) 
    def __str__(self):
        return self.name

class ActionInfo(models.Model):
    name        = models.ForeignKey(ActionName,     related_name="title",    on_delete=models.CASCADE, null=True, blank=True)
    expect_time = models.ForeignKey(ActionDuration, related_name="duration",on_delete=models.CASCADE, null=True, blank=True)
    type        = models.ForeignKey(ActionType,     related_name="type",    on_delete=models.CASCADE, null=True, blank=True)
    available   = models.NullBooleanField(null=True, blank=True, default=True)
    price       = models.ForeignKey(ActionPrice,    related_name="price",   on_delete=models.CASCADE, null=True, blank=True)
---------------------------------------------
</code></pre>

<p>returned json:</p>

<pre><code>{
additional: " 280 Ð Ñ ",
available: true,
comments: null,
discription: "",
expect_time: null,
id: 120,
name: "Ð ÐÐ ÑÐ Â»Ð¡ÐÐ ÐÐ ÑÐ Â°",
photo: "/images/83913-220-184-solyanka_2.jpg",
rate: null,
resource_uri: "/api/v1/action/120/",
type: "Ð ÑÐ ÂµÐ¡ÐÐ ÐÐ¡â¹Ð Âµ Ð Â±Ð Â»Ð¡ÐÐ ÒÐ Â°",
}
</code></pre>

<p>Who knows how to fix it?)</p>

<p>Instead of <code>__str__()</code> use <code>__unicode__()</code>. And use <a href="https://docs.djangoproject.com/es/1.10/ref/utils/#django.utils.encoding.smart_text" rel="nofollow">smart_text</a>:</p>

<pre><code>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)
</code></pre>

<p>BTW: Instead of <code>dehydrate()</code> use fields:</p>

<pre><code>from tastypie import fields

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

    class Meta:
        queryset = ActionInfo.objects.all()
        resource_name = 'action'
</code></pre>

<p>BTW2:</p>

<pre><code>&gt;&gt;&gt; print u'Ð ÐÐ ÑÐ Â»Ð¡ÐÐ ÐÐ ÑÐ Â°'.encode('windows-1251')
Ð¡Ð¾Ð»ÑÐ½ÐºÐ°
&gt;&gt;&gt; print u'Ð ÐÐ ÑÐ Â»Ð¡ÐÐ ÐÐ ÑÐ Â°'.encode('windows-1251').decode('utf8')
Ð¡Ð¾Ð»ÑÐ½ÐºÐ°
</code></pre>

python django unicode utf-8 tastypie