Jahongir Rahmonov
Jahongir Rahmonov

Reputation: 13763

How to change encoding while doing queries in Django

There is this model:

class Currency(CustomBaseModel):
    name = models.CharField(_('name'), max_length=10)

There are two items in the database:

1. сум
2. у.e

These are russian characters. I am doing a simple filter:

Currency.objects.filter(name="сум")

It returns an empty list. I think the problem with encoding.

How to do this?

Upvotes: 0

Views: 61

Answers (2)

Sean
Sean

Reputation: 1

try put this line at the top of your source code:

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

Upvotes: 0

madzohan
madzohan

Reputation: 11808

Django works with unicode. Try Currency.objects.filter(name=u"сум")

Upvotes: 1

Related Questions