我想起来了,我忘了点菜了
from django.db.models.functions import ExtractWeek, ExtractYear from django.db.models.aggregates import Count count = myModel.objects.annotate(year=ExtractYear('created_at')) \ .annotate(week=ExtractWeek('created_at')) \ .values('year','week') \ .annotate(count=Count('id')).order_by('count') <QuerySet [{'year': 2019, 'week': 7, 'count': 8}]>