Q:

How to query set as ORDER BY and GROUP BY in django?

This my is query:
SELECT kategoriharga,ongkoskirim,diskon,ratingproduk,ratingtoko,label 
FROM 
   (SELECT * 
    FROM pohonkeputusan 
    where perdaerah='Kabupaten Toba Samosir' 
    order by label desc
   ) AS sub 
GROUP BY 
kategoriharga,ongkoskirim,diskon,ratingproduk,ratingtoko

How to make to be query set in Django?

A:

I don't understand why you want to group by all fields. Try to use distinct:
Pohonkeputusan.objects.filter(perdaerah='Kabupaten Toba Samosir').order_by('-label').values_list('kategoriharga', 'ongkoskirim', 'diskon', 'ratingproduk', 'ratingtoko').distinct()

