0

I am trying to order a queryset in the view. I get the following Error Message. Kindly help.

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')
Rajkumar R
  • 743
  • 1
  • 10
  • 27
  • possible duplicate of [Postgresql DISTINCT ON without ordering](http://stackoverflow.com/questions/9795660/postgresql-distinct-on-without-ordering) – Anto Apr 23 '14 at 15:51

1 Answers1

0

Have a try with this in the views.py:

op = Op.objects.all().distinct('operator').order_by('operator', 'operator__employeename')
Cphilo
  • 46
  • 11