我必须优化我的查询,因为它们每个需要4分钟,我想这样做但我不知道它的有效,fitting_list是否是查询集列表,但现在它只是一个
转到:
company_list.append(Company.objects.filter(uuid__in=fitting_list.manufacturer.company.uuid).distinct())
address_list.append(Address.objects.filter(company__in=fitting_list.manufacturer.company.uuid).distinct())
customer_list.append(Customer.objects.filter(company__in=fitting_list.manufacturer.company.uuid).distinct())
manufacturer_list.append(Manufacturer.objects.filter(uuid__in=fitting.manufacturer.uuid).distinct())
自:
for fitting_queryset in fitting_list:
for fitting in fitting_queryset:
company_list.append(Company.objects.filter(uuid=fitting.manufacturer.company.uuid).distinct())
address_list.append(Address.objects.filter(company=fitting.manufacturer.company.uuid).distinct())
customer_list.append(Customer.objects.filter(company=fitting.manufacturer.company.uuid).distinct())
manufacturer_list.append(Manufacturer.objects.filter(uuid=fitting.manufacturer.uuid).distinct())