gpt4 book ai didi

python - 从 ValuesQuerySet 访问值

转载 作者:太空宇宙 更新时间:2023-11-04 10:35:07 25 4
gpt4 key购买 nike

obj_l = NewTable.objects.values('country').distinct();

当我打印 obj_l 时,我得到了

[{'country':u'England'},{'country':u'USA'},{'country':u'Russia'}]

当我写 obj_l[0] 时,我得到了

{'country':u'England'}

我只想要像数组中的国家/地区的值

{England,USA,Russia}

我怎样才能做到这一点?

最佳答案

使用values_list()使用 flat=True:

obj_l = NewTable.objects.values_list('country', flat=True).distinct()

关于python - 从 ValuesQuerySet 访问值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23813027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com