/ Django

Writing a Django app for a language that must use UTF-8

Have been writing a Turkish Django app for the past couple of days. The problem is that the Turkish language best works with UTF-8. If you are using MySQL you must make sure that your encoding is utf8_turkish_ci.

# -*- coding: utf-8 -*-

from django.db import models

# Create your models here.
class Category(models.Model):
    name = models.CharField("Kategori Adı",max_length=250)
    exp = models.TextField("Kategori Açıklaması")
    ancestor = models.IntegerField("Kategori Üst Başlığı",max_length=11)
    ancestor.null = True
    ancestor.blank = True
    class Meta:
        verbose_name = u"Kategori"
        verbose_name_plural = u"Kategoriler"

    def __unicode__(self):
        return self.name

You should notice couple of important points here. The most important one being the

# -*- coding: utf-8 -*-

This is important so that Python can understand UTF-8 strings within the model.

I hope this solves couple of questions you might have.

John Roach

John Roach

I am John Roach, a devops architect. Find more information here: https://johnroach.io/about/

Read More
Writing a Django app for a language that must use UTF-8
Share this