【发布时间】:2012-10-05 12:43:05
【问题描述】:
我需要对项目查询集进行排序,引入过时的内容。 (内容是与 Item 类相关的多对多)。 是否可以通过注释中的 pub_date 过滤内容?
我的代码适用于每个内容发布日期。我需要 annotate 函数来处理“pub_date > '2012-10-10'”(例如)。
self.queryset = Item.objects.all()
self.queryset = self.queryset.annotate(
Count("content")).order_by("-content__count")
我尝试使用 extra() 函数进行过滤,但不起作用:
self.queryset = self.queryset.extra(select={
'content': "pub_date > '2012-10-10'"}).annotate(
Count("content")).order_by("-content__count")
【问题讨论】:
标签: django sorting django-queryset annotate