[英]saving datetimefiled in django models, int() argument must be a string or a number
This is my django model 这是我的django模型
class Mymodel(models.Model):
email = models.ForeignKey(EmailAddress)
created = models.DateTimeField(default=timezone.now)
I'm tying to create an model instance and tring to save it like This 我想要创建一个模型实例,并将其保存为像This
x = Mymodel(email_object,timezone.now()) x = Mymodel(email_object,timezone.now())
x.save() x.save()
then its giving this error 然后它给出了这个错误
TypeError: int() argument must be a string or a number, not 'datetime.datetime'
Instead of timezone.now() I stored time as string ,then its giving this error 而不是timezone.now()我将时间存储为字符串,然后它给出了这个错误
ValueError: invalid literal for int() with base 10: '2014-11-29 06:00:00.000000 08:00'
How can I fix this .. please help me.. in which format I have to send the datetime object 我怎么能解决这个问题..请帮帮我..我必须以哪种格式发送datetime对象
Try this: 尝试这个:
created = models.DateTimeField(auto_now_add=True)
There is also auto_now
for an 'updated on' field. “更新后”字段还有
auto_now
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.