Hello I am working on a website and have a question why this is returning the way it is?
I want select distinct ‘category’ from {table}
I tried both with and without Flat = True
In [27]: q = EyeMakeUpWaxing.objects.values_list('category', flat=True).distinct()
In [28]: print q.query
SELECT DISTINCT `eye_make_up_waxing`.`category`, `eye_make_up_waxing`.`created_at` FROM `eye_make_up_waxing` ORDER BY `eye_make_up_waxing`.`created_at` ASC
In [29]: print q
[u'EYE_BEAUTIFICATION', u'EYE_BEAUTIFICATION', u'EYE_BEAUTIFICATION', u'MAKE_UP', u'MAKE_UP', u'MAKE_UP', u'MAKE_UP', u'ENHANCER_ADD_ON', u'ENHANCER_ADD_ON', u'ENHANCER_ADD_ON', u'ENHANCER_ADD_ON', u'ENHANCER_ADD_ON', u'ENHANCER_ADD_ON', u'ENHANCER_ADD_ON']
If this is not the django syntax for this plz help in getting the correct
There is an ordering statement in there causing issues (from default ordering defined in your models / somewhere else).
Clear the ordering via
order_by()The ordering is forcing a SELECT created_at which makes each of those entries distinct.
https://docs.djangoproject.com/en/dev/ref/models/querysets/#distinct