亲爱的 StackOverFlow 社区:
我需要您的帮助来执行以下 SQL 查询。
select DATE(creation_date), COUNT(creation_date) from blog_article WHERE creation_date BETWEEN SYSDATE() - INTERVAL 30 DAY AND SYSDATE() GROUP BY DATE(creation_date) AND author="scott_tiger";
这是我的 Django 模型
class Article(models.Model):
title = models.CharField(...)
author = models.CharField(...)
creation_date = models.DateField(...)
如何使用 aggregate() 和 annotate() 函数形成上述 Django 查询。我创造了这样的东西 -
now = datetime.datetime.now()
date_diff = datetime.datetime.now() + datetime.timedelta(-30)
records = Article.objects.values('creation_date', Count('creation_date')).aggregate(Count('creation_date')).filter(author='scott_tiger', created_at__gt=date_diff, created_at__lte=now)
当我运行此查询时,它给了我以下错误 -
'Count' object has no attribute 'split'
知道谁使用它吗?