Alex Rivera | Logout

Django Model - Get distinct value list

Asked 2012-06-01T10:44:11.667
85

I try to get a list of distinct foreign keys and I wrote this:

my_ids = Entity.objects.values('foreign_key').distinct()

But I get just a list of UNDISTINCT foreign keys... What am I missing?

Thanks!

Edit
Report

1 Answer

72

Passing an argument to distinct doesn't work for MySQL-databases (AFAIK)

This one works and returns just one object:

Entity.objects.order_by('foreign_key').values('foreign_key').distinct()

answered 2012-06-01T11:15:29.390

Your Answer