django做django有一个自动时间戳创建/更新字段像cakephp? [英] django does django have an automatic timestamp create/update field like cakephp?

查看:311
本文介绍了django做django有一个自动时间戳创建/更新字段像cakephp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去使用过cakephp,有一件事(可能唯一的事情)?我喜欢它是有一个创建和更新的时间戳功能是可爱的 - 简单地说,当你第一次添加一个项目,创建日期设置(假设你命名正确 - create_date,我想)



此后,如果执行更新,更新字段为设置为当前时间。



还有django吗?如果是这样,我怎么命名字段来接收它们?

解决方案

确实有!在 auto_now 和 auto_now_add

://docs.djangoproject.com/en/dev/ref/models/fields/#datetimefield>该文档


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?

解决方案

Sure it has!

Check auto_now and auto_now_add in the doc

这篇关于django做django有一个自动时间戳创建/更新字段像cakephp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆