0
我有一個模型:保存浮到FloatField的Django模型,爲什麼強迫爲Unicode:需要字符串或緩衝區,浮動發現
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
我有數據加載到從谷歌docs.I進口模型「米節能是像這樣:
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
做我的T溫度值需要保存爲一個字符串,因爲如果我這樣做,那麼事情就會起作用。只是似乎集市。
我猜我以爲__unicode __(個體經營)將返回unicode字符串。非常感謝! – brownshoes 2014-09-22 13:46:01