简体   繁体   English

在django模型中保存datetimefiled,int()参数必须是字符串或数字

[英]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.

相关问题 Django保存新记录,int()参数必须是字符串或数字,而不是'QueryDict' - Django Saving new record, int() argument must be a string or a number, not 'QueryDict' django - int参数必须是字符串或数字,而不是'元组' - django - int argument must be a string or a number, not 'Tuple' Django int()参数必须是字符串或数字 - Django int() argument must be a string or a number int()参数必须是字符串或数字,而不是django中的'SimpleLazyObject' - int() argument must be a string or a number, not 'SimpleLazyObject' in django Django:int()参数必须是字符串或数字,而不是'Plain' - Django : int() argument must be a string or a number, not 'Plain' Django-TypeError:int()参数必须是字符串或数字,而不是'dict' - Django - TypeError: int() argument must be a string or a number, not 'dict' int() 参数必须是字符串或数字 - int() argument must be a string or a number Django TypeError int()参数必须是字符串或数字,而不是'QueryDict' - Django TypeError int() argument must be a string or a number, not 'QueryDict' Django错误:TypeError:int()参数必须是字符串或数字,而不是“ BuildsTable” - Django Error: TypeError: int() argument must be a string or a number, not 'BuildsTable' Django Allauth-int()参数必须是字符串或数字,而不是'ReverseSingleRelatedObjectDescriptor' - Django Allauth - int() argument must be a string or a number, not 'ReverseSingleRelatedObjectDescriptor'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM