为什么django-lint告诉我“auto_now_add”已被弃用? [英] Why does django-lint tell me the `auto_now_add` is deprecated?

查看:381
本文介绍了为什么django-lint告诉我“auto_now_add”已被弃用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好Djangonauts:

Hi fellow Djangonauts:

我使用 django-lint ,它产生:

W:211,16:MyModel: timestamp: Uses superceded auto_now or auto_now_add

提交信息

auto_now/auto_now_add not technically deprecated, but they still suck.

为什么他们说auto_now / auto_now_add吸?使用这两个字段参数实现创建/上次更新模式时,我没有问题。

Why do they say auto_now/auto_now_add "suck"? I had no problem implementing the created/last-updated pattern with these two field parameters.

这种模式有更好的方法吗?自定义字段类?为什么(如果这种方法更好)它还没有被整合到Django?

Is there a better approach for this pattern? Custom Field classes? And why (if this approach is better) it hasn't been integrated into Django?

推荐答案

正确的修复是通过可以作为字段的默认值返回适当的日期时间,例如 datetime.datetime.now

The correct fix is to pass a callable as the field's default that returns the appropriate datetime, e.g. datetime.datetime.now.

这篇关于为什么django-lint告诉我“auto_now_add”已被弃用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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