这是我的django模型
class Mymodel(models.Model):
email = models.ForeignKey(EmailAddress)
created = models.DateTimeField(default=timezone.now)
我想创建一个模型实例并尝试像这样保存它
x = Mymodel(email_object,timezone.now())
x.保存()
然后它给出了这个错误
TypeError: int() 参数必须是字符串或数字,而不是“datetime.datetime”
我将时间存储为字符串而不是 timezone.now(),然后出现此错误
ValueError:对于基数为 10 的 int() 无效文字:'2014-11-29 06:00:00.000000 08:00'
我该如何解决这个问题..请帮助我..我必须以哪种格式发送日期时间对象
最佳答案
试试这个:
created = models.DateTimeField(auto_now_add=True)
还有用于“更新时间”字段的 auto_now
。
关于python - 在 django 模型中保存 datetimefiled,int() 参数必须是字符串或数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27199508/