How to obtain a QuerySet of all rows, with specific fields for each one of them?

后端 未结 6 1100
情话喂你
情话喂你 2021-01-30 12:20

I have a model Employees and I would like to have a QuerySet of all rows, but with some specific fields from each row, and not all fields.

I know how to quer

6条回答
  •  深忆病人
    2021-01-30 12:38

    Employees.objects.values_list('eng_name', flat=True)
    

    That creates a flat list of all eng_names. If you want more than one field per row, you can't do a flat list: this will create a list of tuples:

    Employees.objects.values_list('eng_name', 'rank')
    

提交回复
热议问题