Django DurationField default

自作多情 提交于 2019-12-05 20:22:16

The default should be a timedelta. This is a bug in Django and is set to be fixed in the 1.8.1 release. See: https://code.djangoproject.com/ticket/24566

So pause = DurationField(default=timedelta(minutes=20)) Should work with the 1.8.1 release.

You mixed up the order of things slightly:

pause = DurationField(default=int(timedelta(minutes=20).total_seconds()))

As mentioned, integers don't have a total_seconds() attribute. Rather, it is an instance method of timedelta.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!