Select DISTINCT individual columns in django?

前端 未结 4 2094
悲&欢浪女
悲&欢浪女 2020-11-28 04:10

I\'m curious if there\'s any way to do a query in Django that\'s not a \"SELECT * FROM...\" underneath. I\'m trying to do a \"SELECT DISTINCT columnName F

4条回答
  •  半阙折子戏
    2020-11-28 04:51

    User order by with that field, and then do distinct.

    ProductOrder.objects.order_by('category').values_list('category', flat=True).distinct()
    

提交回复
热议问题