之前用flask+sqlalchemy可以得出如下效果
其中在Models类里是这样实现的
def get_date(cls):
return db.session.query(extract('month',cls.created_at).label('month'),
extract('year',cls.created_at).label('year'),
func.count('*').label('count')).group_by('month').all()
这样可以得出年(year)、月(month)、总数(count)三个值。
现在要用django的ORM该如何去取出这三个值,实现相同的效果?
参见:http://stackoverflow.com/questions/8746014/django-group-sales-by-month