On Fri, Jun 19, 2009 at 12:18 PM, goobee <[email protected]> wrote:

>
> hi
> I run in problems with umlaute (äöü) with two related tables on a
> postgres-DB
>
> class Rorg(models.Model):
>    rorgokbez = models.CharField(max_length=4, primary_key=True)
>    rorgobez = models.CharField(max_length=30)
>    ....
>    def __unicode__(self):
>        return "%s %s" % (self.rorgokbez, self.rorgobez)
>
>
> class Sore(models.Model):
>  soreokbez=models.ForeignKey(Rorg,
> to_field='rorgokbez',db_column='soreokbez')
>  soreenum=models.IntegerField(primary_key = True)
>  sorebez=models.CharField(max_length=30)
>  ......
>  def __unicode__(self):
>        return "%s %s" % (str(self.soreokbez), self.sorebez)
>

__unicode__ is supposed to return a unicode value.  You've coded it to
return a bytestring.  It needs to be:

def __unicode__(self):
       return u"%s %s" % (self.soreokbez, self.sorebez)


>
>
> Rorg.rorgbez contains values with umlaute. Reading those with
> 'Rorg.objects.get' or '..filter' works fine.  But when I try getting
> data from Sore with a foreign key to Rorg I only get "bad unicode
> data". (btw reading Sore without the foreign key to Rorg works fine as
> well)
>

If you return a bytestring  from your __unicode__ method then you will see
problems like this as Python will try to convert your bytestring to unicode
using the ascii codec, which will raise an exception for any non-ASCII
chars.  The fix is to correct your __unicode__ methods so that they always
return unicode.

Karen

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to