Skip to content

Commit

Permalink
Display Product inventory count on the Product list view #81
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <tdruez@nexb.com>
  • Loading branch information
tdruez committed May 14, 2024
1 parent 8827373 commit 372e97a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@
{% endif %}
</td>
<td>{{ product.configuration_status|default_if_none:'' }}</td>
<td>
{% if product.productinventoryitem_count %}
<a href="{% inject_preserved_filters product.get_absolute_url %}#inventory">{{ product.productinventoryitem_count }}</a>
{% else %}
0
{% endif %}
</td>
<td>
<ul class="fa-ul ms-4 mb-0">
{% for keyword in product.keywords %}
Expand Down
3 changes: 3 additions & 0 deletions product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from django.core.paginator import Paginator
from django.db import models
from django.db import transaction
from django.db.models import Count
from django.db.models.functions import Lower
from django.forms import modelformset_factory
from django.http import Http404
Expand Down Expand Up @@ -147,6 +148,7 @@ class ProductListView(
Header("primary_language", "Language", filter="primary_language"),
Header("owner", "Owner"),
Header("configuration_status", "Status", filter="configuration_status"),
Header("inventory", "Inventory", help_text="Inventory count"),
Header("keywords", "Keywords", filter="keywords"),
)

Expand Down Expand Up @@ -175,6 +177,7 @@ def get_queryset(self):
.prefetch_related(
"licenses__usage_policy",
)
.annotate(productinventoryitem_count=Count("productinventoryitem"))
)

def get_extra_add_urls(self):
Expand Down

0 comments on commit 372e97a

Please sign in to comment.