在django中排序列表时出错

时间:2014-04-23 14:02:03

标签: django django-queryset

我正在尝试在视图中订购一个查询集。我收到以下错误消息。请帮助。

SELECT DISTINCT ON expressions must match initial ORDER BY expressions

models.py

class Op(models.Model):
    operator = models.ForeignKey(Employee, null=False)
    role = models.ForeignKey(Process, null=False)

views.py

op = Op.objects.all().distinct('operator').order_by('operator__employeename')

1 个答案:

答案 0 :(得分:0)

views.py

中尝试使用此功能
op = Op.objects.all().distinct('operator').order_by('operator', 'operator__employeename')