Change text_factory in Django/sqlite

Posted by Krumelur on Stack Overflow See other posts from Stack Overflow or by Krumelur
Published on 2010-04-30T13:00:48Z Indexed on 2010/04/30 13:07 UTC
Read the original article Hit count: 257

Filed under:
|
|
|

I have a django project that uses a sqlite database that can be written to by an external tool. The text is supposed to be UTF-8, but in some cases there will be errors in the encoding. The text is from an external source, so I cannot control the encoding. Yes, I know that I could write a "wrapping layer" between the external source and the database, but I prefer not having to do this, especially since the database already contains a lot of "bad" data.

The solution in sqlite is to change the text_factory to something like: lambda x: unicode(x, "utf-8", "ignore")

However, I don't know how to tell the Django model driver this.

© Stack Overflow or respective owner

Related posts about django

Related posts about python