Unicode issue in Django
Posted
by
Kave
on Stack Overflow
See other posts from Stack Overflow
or by Kave
Published on 2012-09-11T21:35:38Z
Indexed on
2012/09/11
21:38 UTC
Read the original article
Hit count: 516
I seem to have a unicode problem with the deal_instance_name
in the Deal model.
It says:
coercing to Unicode: need string or buffer, __proxy__ found
The exception happens on this line:
return smart_unicode(self.deal_type.deal_name) + _(u' - Set No.') + str(self.set)
The line works if I remove smart_unicode(self.deal_type.deal_name)
but why?
Back then in Django 1.1 someone had the same problem on Stackoverflow I have tried both the unicode()
as well as the new smart_unicode()
without any joy.
What could I be missing please?
class Deal(models.Model):
def __init__(self, *args, **kwargs):
super(Deal, self).__init__(*args, **kwargs)
self.deal_instance_name = self.__unicode__()
deal_type = models.ForeignKey(DealType)
deal_instance_name = models.CharField(_(u'Deal Name'), max_length=100)
set = models.IntegerField(_(u'Set Number'))
def __unicode__(self):
return smart_unicode(self.deal_type.deal_name) + _(u' - Set No.') + str(self.set)
class Meta:
verbose_name = _(u'Deal')
verbose_name_plural = _(u'Deals')
Dealtype:
class DealType(models.Model):
deal_name = models.CharField(_(u'Deal Name'), max_length=40)
deal_description = models.TextField(_(u'Deal Description'), blank=True)
def __unicode__(self):
return smart_unicode(self.deal_name)
class Meta:
verbose_name = _(u'Deal Type')
verbose_name_plural = _(u'Deal Types')
© Stack Overflow or respective owner