On Tue, Jun 8, 2010 at 3:19 AM, zayatzz <alan.kesselm...@gmail.com> wrote:

> > Guarantee the problem is with your __unicode__ method on the Game
> > model, in that case (it's probably not returning unicode). Even though
> > the admin is now working, you should fix it or you'll almost certainly
> > get unexpected 500 errors later.
> > --
> > DR.
>
> Yes thats what i guessed from it myself. But im not sure how to fix
> this.
> def __unicode__(self):
>            return u"%s vs %s" % ( u"self.teamone", u"self.teamtwo" )
>
> perhaps?
>
>
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?

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.)

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.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to