queryset = (
Product.objects.select_related("brand", "product_grade")
.filter(filters)
.order_by(sorter)
.prefetch_related(
"productthumbnail_set",
"pricehistory_set",
"productdetail_set",
"useruploadproductimage_set",
)
.distinct()[offset: offset + limit]
)
for product in queryset:
... (생략) ...
order_by를 사용하면 매번 쿼리를 한다.
queryset = list(
Product.objects.select_related("brand", "product_grade")
.filter(filters).order_by(sorter)
.prefetch_related(
"productthumbnail_set",
"pricehistory_set",
"productdetail_set",
"useruploadproductimage_set",
)
)
for product in queryset[offset: offset + limit]:
... (생략) ...