【发布时间】:2014-09-21 17:07:32
【问题描述】:
我有一个模型:
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
我有数据要加载到从谷歌文档导入的模型中。我保存的是这样的:
conditions_obj = Conditions.objects.get_or_create(
date_time=datetime.datetime.strptime(row[0],'%m/%d/%Y %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S'),
temperature=float(row[1]),
humidity=float(row[2]))
当我这样做时,我得到了这个错误,我不确定为什么:
TypeError: coercing to Unicode: need string or buffer, float found
我的温度值是否需要保存为字符串,因为如果我这样做了,那么一切正常。只是看起来像集市。
【问题讨论】: