feat: added prefetch related for product prices
This commit is contained in:
@@ -29,7 +29,9 @@
|
|||||||
<!-- </div>-->
|
<!-- </div>-->
|
||||||
<div class="mt-4 flex gap-4">
|
<div class="mt-4 flex gap-4">
|
||||||
<p class="txt-2xl">
|
<p class="txt-2xl">
|
||||||
{{ product.price.price_with_tax }}€
|
{% with product.current_prices.0 as price %}
|
||||||
|
{{ price.price_with_tax }} €
|
||||||
|
{% endwith %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
from django.db.models import Prefetch
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import get_object_or_404, render
|
from django.shortcuts import get_object_or_404, render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@@ -29,6 +30,7 @@ class ListProducts(TemplateView, FilteredQuerysetMixin, PaginatedQuerysetMixin):
|
|||||||
template_name = "web/list_products.html"
|
template_name = "web/list_products.html"
|
||||||
queryset = Product.objects.filter(hidden=False).prefetch_related(
|
queryset = Product.objects.filter(hidden=False).prefetch_related(
|
||||||
"images",
|
"images",
|
||||||
|
Prefetch("prices", queryset=ProductPrice.objects.filter(current=True), to_attr="current_prices")
|
||||||
)
|
)
|
||||||
filter_class = ProductFilter
|
filter_class = ProductFilter
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user