0

我正在检索一组不同的(不同类/模型的)对象

items = tagging.models.TaggedItem.objects.distinct().filter(tag__name__in=tagslist)

所有这些对象都必须具有 pub_date 字段,我想按该字段对它们进行排序。

有任何想法吗?非常感谢。

伊戈尔

4

1 回答 1

0

编辑:我误解了这个问题。您需要使用常规 python 代码对它们进行排序,因为您将无法引用 order_by 的原始对象

由于 items 是一个 QuerySet,您可以将order_by()调用链接到您的filter()调用上,如下所示:

items = tagging.models.TaggedItem.objects.distinct().filter(tag__name__in=tagslist).order_by(pub_date)
于 2012-01-05T14:21:17.263 回答