Django优化了查询集

时间:2012-06-05 09:31:48

标签: sql django optimization

我想这样做:

emails = [c.email for c in Client.objects.all().order_by('lastname', 'firstname')]

是否有更好的方法可以查询SELECT email from clients ORDER BY lastname, firstname

1 个答案:

答案 0 :(得分:7)

Client.objects.order_by('lastname', 'firstname').values_list('email', flat=True)