Select DISTINCT individual columns in django?

前端 未结 4 2053
悲&欢浪女
悲&欢浪女 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 05:01

    It's quite simple actually if you're using PostgreSQL, just use distinct(columns) (documentation).

    Productorder.objects.all().distinct('category')
    

    Note that this feature has been included in Django since 1.4

提交回复
热议问题