Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django does django have an automatic timestamp create/update field like cakephp?

Tags:

django

having used cakephp in the past, one thing (perhaps the only thing?) i liked about it was that it had a "create" and "update" timestamp capability that was lovely - simply put, when you first added an item, the "create" date was set (assuming you named it right - create_date, i think)

Anytime thereafter, if an update was performed, the "update" field was set to the current time.

Does django have this as well? If so, what/how do i name the fields to get it to pick them up?

like image 412
bharal Avatar asked Jun 11 '12 11:06

bharal


2 Answers

It is not added to your model built-in in every table. You must add it as field to your model.

class Message(models.Model):

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

Message in this case your table's name.

like image 156
Sayonara Avatar answered Oct 01 '22 06:10

Sayonara


Sure it has!

Check auto_now and auto_now_add in the doc

like image 32
okm Avatar answered Oct 01 '22 04:10

okm