一起使用distinct()order_by()filter()

时间:2020-05-27 15:44:48

标签: python django orm

我有一个查询:

titles= Entry.objects.filter(created_date__gte=date_from,user__followed__follower=request.user).order_by('-created_date').values_list('title', flat=True).distinct()

它工作正常,除了不可用的不同部分以及我使用的数据库不支持distinct(“ title”)。在查询对象上执行set()而不使用distinct()会破坏顺序。我想出的唯一解决方案是将列表中的每个标题附加在列表中,然后检查列表中是否已经存在,这可能是一个过大的错误。

感谢您阅读。

0 个答案:

没有答案
相关问题