This __unicode__ method. It returns unicode. It does not, however,
reference the attributes teamone and teamtwo, but instead always
renders the string u"self.teamone vs self.teamtwo". Putting self.teamone
and self.teamtwo in quotes makes them just strings, not references to
attributes of self. That's fine if that's what you wanted.
But if you were simply trying to coerce them to unicode before passing
them to the % operator, that's actually unnecessary since % with a
left hand operand that is a unicode string will coerce it's format results
to unicode. But if you really needed to do that, the way to go is:
return u"%s vs %s" % (unicode(self.teamone), unicode(self.teamtwo))
But if the value of self.teamone or self.teamtwo is a UTF-8 encoded byte
string while the default encoding is ASCII, you will still get the decoding
error. You might want to try:
return u"%s vs %s" % (self.teamone.decode('utf-8'),
self.teamtwo.decode('utf-8')
This will get the wrong answer if the values are actually in some
other encoding,
such as latinN, but it may work correctly if the values are already unicode.
But this may not be where your original issue came from. You might temporarily
add code that checks whether they are byte strings versus unicode already,
and adds a label to the result. Or, if you always expect unicode (probably
what a character field read from the database is by default in the typical DB
configuration), you could raise an exception if it is not, while holding lots of
interesting stuff in local varuables so that they could be examined in the
stack trace.
Bill
On Tue, Jun 8, 2010 at 3:19 AM, zayatzz <[email protected]> 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?
>
> 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.
>
>
--
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.