【发布时间】:2019-08-16 00:10:59
【问题描述】:
我正在使用 Django、Python 3.7 和 PostGres 9.5。我想在 Django 中编写以下 WHERE 子句...
WHERE date_part('hour', current_time) = s.hour ...
所以在阅读其他一些文档时,我被引导相信我需要在运行查询之前编写一个“Func”创建一个注释......
qset = ArticleStat.objects.annotate(
hour_of_day=Func(
'current_time',
Value('hour'),
function='date_part',
)
).filter(hour_of_day=F("article__website__stats_per_hour__hour"))
但是,这会导致
Cannot resolve keyword 'current_time' into field. Choices are: article, article_id, elapsed_time_in_seconds, id, score
错误。似乎 Django 正在尝试将“current_time”视为我表中的一列,但我真的希望它被视为 PostGres 函数。我该怎么做?
【问题讨论】:
标签: python django python-3.x postgresql func