convert a django queryset into an array

后端 未结 2 1870
耶瑟儿~
耶瑟儿~ 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 03:44

    def get_array(Table, column):
        rows = Table.objects.values(column)
        return [row[column] for row in rows]
    
    print get_array(Users, 'firstnames')
    

提交回复
热议问题