created_at = models.DateTimeField(editable=False)
updated_at = models.DateTimeField() def save(self, *args, **kwargs): ''' On save, update timestamps ''' if not self.id: self.
created_at
= timezone.now()
self.
updated_at =
self.
self.
created_at
updated_at = timezone.now() return super(User, self).save(*args, **kwargs)
El miércoles, 28 de noviembre de 2018, 3:13:03 (UTC-4), Ankit Khandewal escribió:
hello, i am using this code to update created_at and updated_at in models:created_at = models.DateTimeField(auto_now_add=True) updated_at= models.DateTimeField(auto_now=True,null=True) but however there is created _at is greater than updated_at when data is inserted:created_at -> 2018-11-26 11:11:30.020989updated_at -> 2018-11-26 11:11:30.019762please help, thank you.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0057a8c6-731d-4fd9-8fa3-48f764485ef9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment