> > That's just going to result in every game showing up as "self.teamone vs > self.teamtwo". Your original definition: > > def __unicode__(self): > return u"%s vs %s" % ( self.teamone, self.teamtwo ) > > is correct, assuming (and this may be where the problem is) the database is > returning unicode strings for your character fields. Based on the behavior, > it sounds like it is not. Looking back at the original thread I see a > mention of using MySQL with a non-default collation (utf8_unicode_ci). I > cannot recreate any problem using this collation, so one question I have is > what collation are you using? What is the output of 'show create table' for > this table?
CREATE TABLE `game_game` ( `id` int(11) NOT NULL AUTO_INCREMENT, `type` smallint(5) unsigned NOT NULL, `teamone` varchar(100) COLLATE utf8_bin NOT NULL, `teamonescore` int(11) DEFAULT NULL, `teamtwo` varchar(100) COLLATE utf8_bin NOT NULL, `teamtwoscore` int(11) DEFAULT NULL, `gametime` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 COLLATE=utf8_bin > > The behavior you are seeing is consistent with the database being configured > to use a binary collation (e.g. utf8_bin). When a MySQL column is configured > to use a binary collation, the database adapter (MySQLdb) returns its data > as a bytestring instead of unicode, and you will see errors like this one > you have reported. The fix in that case would be to do something like: > > from django.utils.encoding import smart_unicode > def __unicode__(self): > return u"%s vs %s" % (smart_unicode(self.teamone), > smart_unicode(self.teamtwo)) > > (This will only work if the database encoding in use is actually utf8 -- if > it is something else you'd need to pass whatever it is as an encoding > parameter to smart_unicode.) well. since im no programming whizard and so far i have not needed to delve deep into encoding/decoding issues. I learn about programming as i learn to do stuff :). So i have tried to stick to using default settings - hence utf-8 at mysql. With this app i did not set collation myself. If the collation should be utf8_general_ci_swedish as the link below says, then i probably have set it to utf-8 at some point of installing mysql/phpmyadmin. > > The need to do this when using a binary collation with MySQL is > documented:http://docs.djangoproject.com/en/dev/ref/databases/#collation-settings. > If > in fact this is necessary in some circumstances even when using a non-binary > collation I'd like to understand that -- but in my testing the only way I > can get behavior like what you are seeing is when I set the collation to a > binary one. > Well. It's like you said. If i create the database with swedish_ci, then it works just fine. Looks like i have gaps in my education, but since i dont know where they are i just learn when i stumble upon problems. The link you posted about collation settings taught me alot so if i look at the things from my self interest prespective, i cant see the fault in posting this question. Although to you probably it looks like wasted time :). So just to sum it up - there was actually nothing wrong there, but since i did not know what i was doing i created a fuss over nothing, lol :) Otherwise the behaviour of django was all as it should have been. > Karen > --http://tracey.org/kmt/ Thank you everybody and especially you Karen, this is a second thread into my bookmarks. Alan -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

