mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-21 19:47:20 -06:00
Add tagged items count to tag view
This commit is contained in:
parent
2e07ac5a47
commit
aa2beb1d78
@ -1,7 +1,6 @@
|
||||
from django import template
|
||||
from django.contrib import messages
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import Q
|
||||
from django.db.models import Count, Q
|
||||
from django.http import Http404, HttpResponseForbidden
|
||||
from django.shortcuts import get_object_or_404, redirect, render
|
||||
from django.urls import reverse
|
||||
@ -45,9 +44,17 @@ class TagView(generic.ObjectView):
|
||||
)
|
||||
paginate_table(taggeditem_table, request)
|
||||
|
||||
object_types = [
|
||||
{
|
||||
'content_type': ContentType.objects.get(pk=ti['content_type']),
|
||||
'item_count': ti['item_count']
|
||||
} for ti in tagged_items.values('content_type').annotate(item_count=Count('pk'))
|
||||
]
|
||||
|
||||
return {
|
||||
'taggeditem_table': taggeditem_table,
|
||||
'tagged_item_count': tagged_items.count(),
|
||||
'object_types': object_types,
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,6 +40,27 @@
|
||||
{% plugin_left_page object %}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<strong>Tagged Item Types</strong>
|
||||
</div>
|
||||
<table class="table table-hover panel-body">
|
||||
{% for object_type in object_types %}
|
||||
<tr>
|
||||
<td>{{ object_type.content_type.name|bettertitle }}</td>
|
||||
<td>
|
||||
{% with viewname=object_type.content_type.model_class|validated_viewname:"list" %}
|
||||
{% if viewname %}
|
||||
<a href="{% url viewname %}?tag={{ object.slug }}">{{ object_type.item_count }}</a>
|
||||
{% else %}
|
||||
{{ object_type.item_count }}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% plugin_right_page object %}
|
||||
</div>
|
||||
</div>
|
||||
@ -47,7 +68,7 @@
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<strong>Device Types</strong>
|
||||
<strong>Tagged Items</strong>
|
||||
</div>
|
||||
{% include 'inc/table.html' with table=taggeditem_table %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user