0
我想每月註釋日期標註,並且做到了這一點:Django的近 「距離」:語法錯誤,試圖通過一個月
class Month(Func):
function = 'EXTRACT'
template = '%(function)s(MONTH from %(expressions)s)'
output_field = models.IntegerField()
然後
MyModel.objects.annotate(month=Month('visited_at'))
.values('month')
.annotate(total=Sum('coins_counted'))
.order_by('month')
而得到錯誤:
OperationalError: near "from": syntax error
任何想法?
您使用了哪個數據庫?我與SQLITE有類似的問題,而同樣的代碼與Postgres運行良好。 SQLITE具有非常有限的聚合函數:https://www.sqlite.org/lang_aggfunc.html – Davy