django查询中values_list(flat=True) 是什么意思?

1.values()

departments = models.Department.objects.filter(dpm_status=1).values('dnp__name')
print(departments )

  # queryset中是一个个字典。“departments”:[{"dnp__name":"运输部门"},{"dnp__name":"仓储部门"}]

2.values_list()

departments = models.Department.objects.filter(dpm_status=1).values_list('dnp__name')
print(departments )

  # queryset中是一个个元组。“departments”:[("运输部门",),("仓储部门",)]

3.values_list(flat=True)

departments = models.Department.objects.filter(dpm_status=1).values_list('dpm_name', flat=True)
print(departments)

  # queryset中是一个列表。 “departments”:["运输部门","仓储部门"]

 

posted on 2022-12-28 17:09  一先生94  阅读(538)  评论(0编辑  收藏  举报

导航