i'm having problems when adding elements in django interface. have 2 definitions:
# -*- coding: utf-8 -*- class visittype(models.model): name=models.charfield(max_length=50,db_index=true,verbose_name="nombre del tipo de visita") is_basal=models.booleanfield(default=false,verbose_name="es basal") def __unicode__(self): if self.is_basal: s="%s [basal]" % (self.name) else: s="%s" % (self.name) return s class visit(models.model): type=models.foreignkey(visittype,null=true,on_delete=models.set(visittype.get_sentinel_visit_type),db_index=false,verbose_name="tipo de visita") def __unicode__(self): return "tipo de visita %s" % (self.type) when adding visittype object in admin site, there no problem. adding_visittype
but, when adding visit in admin: adding_visit
i unicodedecodeerror hint: "the string not encoded/decoded analtica" (notice used "analĂtica" visit type in form.
i'm using django 1.5.1, mysql-python 1.2.4.
the mysql using tables utf8_general_ci collation.
the database mysql 5.5.30.
regards.
neither of __unicode__ methods return unicode strings. both return byte strings. recipe disaster. when inside functions you're interpolating unicode byte strings.
do instead:
def __unicode__(self): if self.is_basal: s = u"%s [basal]" % (self.name) else: s = self.name return s and:
return u"tipo de visita %s" % (self.type)
Comments
Post a Comment