Django Model - Get distinct value list

后端 未结 4 547
说谎
说谎 2020-12-13 23:59

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

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 00:20

    Perhaps you might want to go with this:

    Entity.objects.order_by().values_list('foreign_key', flat=True).distinct()
    

提交回复
热议问题