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')
Rk..
  • 753
  • 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
  • error has vanished but ordering the list is missed. – Rk.. Apr 23 '14 at 14:25
  • You may need have a look at this question: http://stackoverflow.com/questions/9795660/postgresql-distinct-on-without-ordering. – Cphilo Apr 23 '14 at 14:27