Add tagged items count to tag view

This commit is contained in:
jeremystretch
2021-04-05 13:53:25 -04:00
parent e5837a4d7b
commit 4cb1ae0fd1
2 changed files with 31 additions and 3 deletions

View File

@@ -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,
}