deal_instance_name
我似乎在 Deal 模型中遇到了 unicode 问题。
它说:
coercing to Unicode: need string or buffer, __proxy__ found
异常发生在这一行:
return smart_unicode(self.deal_type.deal_name) + _(u' - Set No.') + str(self.set)
如果我删除该行,smart_unicode(self.deal_type.deal_name)
但为什么?
那时在 Django 1.1 中,有人在Stackoverflow上遇到了同样的问题,我尝试unicode()
了新的和新的smart_unicode()
,没有任何快乐。
请问我会错过什么?
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.') + smart_unicode(self.set)
class Meta:
verbose_name = _(u'Deal')
verbose_name_plural = _(u'Deals')
交易类型:
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')