将float保存到floatfieldDjango模型,为什么强制为Unicode:需要字符串或缓冲区,float found

2024-03-29 06:57:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个模型:

 class Conditions(models.Model):
        date_time = models.DateTimeField(blank=True, null=True)
        temperature = models.FloatField(blank=True, null=True)
        humidity = models.FloatField(blank=True, null=True)

        def __unicode__(self):
            return self.temperature

我有数据要加载到从google docs导入的模型中。我保存如下:

^{pr2}$

当我这样做时,我得到了一个错误,我不知道为什么:

TypeError: coercing to Unicode: need string or buffer, float found

我的温度值需要保存为一个字符串,因为如果我这样做,那么事情就正常了。就像是集市。在


Tags: 模型selftruedatemodeltimemodelsnull