Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前有以下列表理解:
[item.service.name for item in OrderItem.objects.all()]
service是一个 FK on OrderItem,所以上面的代码正在做大量无用的 FK 查找。我如何services在一个查询中获得所有信息?
service
OrderItem
services
以下将为您提供所需的内容:
OrderItem.objects.values_list('service__name', flat=True).distinct()