我有一个非常基本的模型:
class Link(models.Model):
title = models.CharField(max_length=250, null=False)
user = models.ForeignKey(User)
url = models.CharField(max_length=250, blank=True, null=True)
link_count = models.IntegerField(default=0)
pub_date = models.DateField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
我可以使用以下方式创建按日期分组的所有条目的列表:
Link.objects.values('pub_date').order_by('-pub_date').annotate(dcount=Count('pub_date'))
这自然会按天分组。但是我真的想做的是一个个月。有没有办法使用annotate()?
非常感谢,
G