optimize product pages again

This commit is contained in:
imperosol 2024-10-20 00:27:25 +02:00
parent b9cbba2309
commit db6a871854
2 changed files with 4 additions and 4 deletions

View File

@ -13,7 +13,7 @@
<h4>{{ product_type or _("Uncategorized") }}</h4> <h4>{{ product_type or _("Uncategorized") }}</h4>
<ul> <ul>
{%- for product in products -%} {%- for product in products -%}
<li><a href="{{ url('counter:product_edit', product_id=product.id) }}">{{ product }} ({{ product.code }})</a></li> <li><a href="{{ url('counter:product_edit', product_id=product.id) }}">{{ product.name }} ({{ product.code }})</a></li>
{%- endfor -%} {%- endfor -%}
</ul> </ul>
{%- else -%} {%- else -%}

View File

@ -17,7 +17,7 @@ import re
from datetime import datetime, timedelta from datetime import datetime, timedelta
from datetime import timezone as tz from datetime import timezone as tz
from http import HTTPStatus from http import HTTPStatus
from operator import attrgetter from operator import itemgetter
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from urllib.parse import parse_qs from urllib.parse import parse_qs
@ -801,7 +801,7 @@ class ProductTypeEditView(CounterAdminTabsMixin, CounterAdminMixin, UpdateView):
class ProductListView(CounterAdminTabsMixin, CounterAdminMixin, ListView): class ProductListView(CounterAdminTabsMixin, CounterAdminMixin, ListView):
model = Product model = Product
queryset = Product.objects.annotate(type_name=F("product_type__name")) queryset = Product.objects.values("id", "name", "code", "product_type__name")
template_name = "counter/product_list.jinja" template_name = "counter/product_list.jinja"
ordering = [ ordering = [
F("product_type__priority").desc(nulls_last=True), F("product_type__priority").desc(nulls_last=True),
@ -812,7 +812,7 @@ class ProductListView(CounterAdminTabsMixin, CounterAdminMixin, ListView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
res = super().get_context_data(**kwargs) res = super().get_context_data(**kwargs)
res["object_list"] = itertools.groupby( res["object_list"] = itertools.groupby(
res["object_list"], key=attrgetter("type_name") res["object_list"], key=itemgetter("product_type__name")
) )
return res return res