I have a MySQL database, right now I’m generating all of the datetime fields as models.DateTimeField. Is there a way to get a timestamp instead? I want to be able to autoupdate on create and update etc.
The documentation on django doesn’t have this?
There was actually a very good and informative article on this. Here:
http://ianrolfe.livejournal.com/36017.html
The solution on the page is slightly deprecated, so I did the following:
To use it, all you have to do is:
timestamp = UnixTimestampField(auto_created=True)In MySQL, the column should appear as:
'timestamp' timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,Only drawback with this is that it only works on MySQL databases. But you can easily modify it for others.