convert a django queryset into an array

后端 未结 2 1868
耶瑟儿~
耶瑟儿~ 2021-02-19 03:27

i would like convert a django queryset into an array like,

firstnames=Users.objects.values(\'firstnames\')

to get a result that looks like

2条回答
  •  爱一瞬间的悲伤
    2021-02-19 04:03

    Use QuerySet.values_list and specify flat=True:

    firstnames = Users.objects.values_list('firstnames', flat=True)
    firstnames = list(firstnames)
    

提交回复
热议问题