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

后端 未结 6 1097
情话喂你
情话喂你 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:49

    You can use values_list alongside filter like so;

    active_emps_first_name = Employees.objects.filter(active=True).values_list('first_name',flat=True)
    

    More details here

提交回复
热议问题