- | {% trans 'Name' %} |
+ {% trans 'Name and comment count' %} |
{% trans 'Address' %} |
{% trans 'The nature of the damage' %} |
{% trans 'Description' %} |
@@ -40,6 +40,7 @@
{{ task.abon.get_full_name }}
+ {% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %}
{{ task.abon.group.title }}, {{ task.abon.street|default:'' }} {{ task.abon.house|default:'' }}
diff --git a/taskapp/templates/taskapp/tasklist_all.html b/taskapp/templates/taskapp/tasklist_all.html
index 6e6b34b..7b9d5f8 100644
--- a/taskapp/templates/taskapp/tasklist_all.html
+++ b/taskapp/templates/taskapp/tasklist_all.html
@@ -19,7 +19,7 @@
- | {% trans 'Name' %} |
+ {% trans 'Name and comment count' %} |
{% trans 'Address' %} |
{% trans 'The nature of the damage' %} |
{% trans 'Description' %} |
@@ -53,6 +53,7 @@
{{ task.abon.get_full_name }}
+ {% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %}
{{ task.abon.group.title }}, {{ task.abon.street|default:_('Not assigned') }} {{ task.abon.house|default:_('Not assigned') }} |
diff --git a/taskapp/views.py b/taskapp/views.py
index 68d3db0..ea1eebb 100644
--- a/taskapp/views.py
+++ b/taskapp/views.py
@@ -3,6 +3,7 @@ from json import dumps
from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
+from django.db.models import Count
from django.shortcuts import redirect, get_object_or_404, resolve_url
from django.contrib import messages
from django.utils.decorators import method_decorator
@@ -37,6 +38,7 @@ class NewTasksView(BaseTaskListView):
def get_queryset(self):
return Task.objects.filter(recipients=self.request.user, state='S') \
+ .annotate(comment_count=Count('extracomment')) \
.select_related('abon', 'abon__street', 'abon__group', 'author')
@@ -85,7 +87,8 @@ class AllTasksListView(BaseTaskListView):
context_object_name = 'tasks'
def get_queryset(self):
- return Task.objects.select_related('abon', 'abon__street', 'abon__group', 'author')
+ return Task.objects.annotate(comment_count=Count('extracomment')) \
+ .select_related('abon', 'abon__street', 'abon__group', 'author')
@login_required
|