feat: added prefetch related for product prices

This commit is contained in:
2025-02-19 19:26:28 +01:00
parent 658f5d6749
commit fe085664d5
2 changed files with 5 additions and 1 deletions
+2
View File
@@ -1,6 +1,7 @@
from decimal import Decimal
from django.db import models
from django.db.models import Prefetch
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
@@ -29,6 +30,7 @@ class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
template_name = "web/list_products.html"
queryset = Product.objects.filter(hidden=False).prefetch_related(
"images",
Prefetch("prices", queryset=ProductPrice.objects.filter(current=True), to_attr="current_prices")
)
filter_class = ProductFilter