一起应用order_by和distinct

时间:2020-06-02 10:33:36

标签: python django-rest-framework

我正在对查询集应用不同

matches = queryset.filter(name__contains=query).distinct('entity_id')

我也不会申请order_by('-count'),即

matches=queryset.filter(name__contains=query).order_by('count').distinct('entity_id')

但出现错误

ProgrammingError at /v1/search/
SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: SELECT DISTINCT ON ("entity"."entity_id") "entity...

如何做到这一点。

0 个答案:

没有答案