Django generally has very good Unicode support (see the Django 1.1 “Unicode data” documentation for details). In my code I find that, if I’m having a problem with simple Unicode features, the problem usually is that I’m not understanding Django’s details well, not that Django has a bug in its Unicode support.

The “Unicode Data” page tells us that “All of Django’s database backends … automatically convert strings retrieved from the database into Python Unicode strings. You don’t even need to tell Django what encoding your database uses: that is handled transparently.” So your simple return self.nombre should return a Python Unicode string.

…if you really want case-sensitive comparisons on a particular column or table, you would change the column or table to use the utf8_bin collation. The main thing to be aware of in this case is that if you are using MySQLdb 1.2.2, the database backend in Django will then return bytestrings (instead of unicode strings) for any character fields it returns receive from the database. This is a strong variation from Django’s normal practice of always returning unicode strings. It is up to you, the developer, to handle the fact that you will receive bytestrings if you configure your table(s) to use utf8_bin collation. Django itself should work smoothly with such columns, but if your code must be prepared to call django.utils.encoding.smart_unicode() at times if it really wants to work with consistent data …

So, in your original example, the column “nombre” used utf8_bin collation. This meant that self.nombre was returning a Python byte string. When you put it in an expression that required a Python Unicode string, Python performed its default conversion. This is the equivalent of self.nombre.decode('ascii'). And of course, .decode('ascii') fails when it encounters any byte above 0×7F, such as the UTF-8 bytes which encode “á”.

You discovered the two ways to solve this problem. The first is to convert the Python byte string returned by self.nombre into a Python Unicode string explicitly. I’ll bet the following simpler code would have worked:

return self.nombre.decode('utf8')

The second approach is to change the MySQL collation for column “nombre”, which causes Django’s MySQL backend to return Python Unicode strings instead of the unusual byte strings. Then your original expression gives a Python Unicode string: