Storing datetimefiled in django models, int () argument must be string or number

This is my django model

class Mymodel(models.Model):

    email = models.ForeignKey(EmailAddress)
    created = models.DateTimeField(default=timezone.now)

      

I am linking to instantiate the model and tring to store it like This

x = Mymodel (email_object, timezone.now ())

x.save ()

then it gives this error

TypeError: int() argument must be a string or a number, not 'datetime.datetime'

Instead of timezone.now () I saved the time as a string and then gave this error

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 .. what format do I need to send the datetime object in

+3


source to share


1 answer


Try the following:

created = models.DateTimeField(auto_now_add=True)



There is also an auto_now

"updated" field.

+2


source







All Articles