且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django按月份注释分组

更新时间:2023-01-29 20:48:38

如果您使用PostgreSQL,以下内容可能会起作用:

If you're on PostgreSQL, the following might work:

from django.db.models import Count

Link.objects.extra(select={'month': 'extract( month from pub_date )'}).values('month').annotate(dcount=Count('pub_date'))

我不知道如何便携式提取是跨其他数据库。

I'm not sure how portable extract is across other databases.