Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add more informations to ProductClass list

Krzysztof Wolski5bea99578575
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.py
index 6dd878abbf..331f6fecdf 100644
--- a/saleor/dashboard/product/views.py
+++ b/saleor/dashboard/product/views.py
@@ -18,11 +18,16 @@ from ..views import staff_member_required
@staff_member_required
def product_class_list(request):
- classes = ProductClass.objects.all()
+ classes = ProductClass.objects.all().prefetch_related(
+ 'product_attributes', 'variant_attributes')
form = forms.ProductClassForm(request.POST or None)
if form.is_valid():
return redirect('dashboard:product-class-add')
classes = get_paginator_items(classes, 30, request.GET.get('page'))
+ classes.object_list = [
+ (pc.pk, pc.name, pc.has_variants, pc.product_attributes.all(),
+ pc.variant_attributes.all())
+ for pc in classes.object_list]
ctx = {'form': form, 'product_classes': classes}
return TemplateResponse(request, 'dashboard/product/class_list.html', ctx)
diff --git a/templates/dashboard/product/class_list.html b/templates/dashboard/product/class_list.html
index ba313ebc42..38bd8ee495 100644
--- a/templates/dashboard/product/class_list.html
+++ b/templates/dashboard/product/class_list.html
@@ -33,12 +33,16 @@
<div class="col s12">
{% if product_classes %}
<ul class="collection list">
- {% for product_class in product_classes %}
+ {% for pk, name, has_variants, product_attributes, variant_attributes in product_classes %}
<li class="collection-item list-item">
- <a class="title" href="{% url 'dashboard:product-class-update' pk=product_class.pk %}">
- <span class="list-item-name">{{ product_class.name }}</span>
+ <a class="title" href="{% url 'dashboard:product-class-update' pk=pk %}">
+ <span class="list-item-name">{{ name }}</span>
</a>
- <p>{% trans 'Variants' %}: {% if product_class.has_variants %}{% trans 'Yes' %}{% else %}{% trans 'No' %}{% endif %}</p>
+ <p>
+ {% trans 'Variants' %}: {% if has_variants %}{% trans 'Yes' %}{% else %}{% trans 'No' %}{% endif %}
+ {% if variant_attributes %} | {% trans 'Variant attributes' %}: {{ variant_attributes|join:", " }}{% endif %}
+ {% if product_attributes %} | {% trans 'Product attributes' %}: {{ product_attributes|join:", " }}{% endif %}
+ </p>
</li>
{% endfor %}
</ul>