I would like a timestamp field updating each time the record is modified like in MySQL.
DateTimeField(default=datetime.datetime.now()) will only set it the first time it is created...
Any have a simple solution? Is the only solution is to manually set the Column options in MySQL db?
An auto-updated column is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. An auto-updated column remains unchanged if all other columns are set to their current values.
With the DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP, a column has the current timestamp for its default value and is automatically updated to the current timestamp.
You can override the save method on your model class.
class Something(Model):     created = DateTimeField(default=datetime.datetime.now)     modified = DateTimeField      def save(self, *args, **kwargs):         self.modified = datetime.datetime.now()         return super(Something, self).save(*args, **kwargs) If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With