3
我需要比较同一周(isocalendar)中的事件总数,年比。Django查询去年同一周
class MyModel(models.Model):
date = models.DateTime(...
hits = models.IntegerField(...
我有了这个排序去年,上个月,去年同月,同日去年使用上的变化:
same_month_last_year = MyModel.objects.filter(date__month = (datetime.datetime.now().month), date__year = (datetime.datetime.now() - relativedelta(years = 1)).year).aggregate(total=Sum('hits')['total']
我没有看到一个相当于“周”功能。我可以在等式右边使用.isocalendar()[1],但这对左边没有任何帮助。有任何想法吗?谢谢。
完美的解决方案。 – William