所有这些功能都可以从django.contrib.postgres.functions
模块中获得。
TransactionNow
¶返回当前事务启动的数据库服务器上的日期和时间。 如果您不在交易中,它将返回当前语句的日期和时间。 这是对django.db.models.functions.Now
的补充,它返回当前语句的日期和时间。
Note that only the outermost call to atomic()
sets up a transaction and thus sets the time that TransactionNow()
will
return; nested calls create savepoints which do not affect the transaction
time.
用法示例:
>>> from django.contrib.postgres.functions import TransactionNow
>>> Article.objects.filter(published__lte=TransactionNow())
<QuerySet [<Article: How to Django>]>
2017年9月6日