From 439e8676fdab38012ed1b5b90f03a6fda24bb6bf Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Tue, 27 Feb 2018 17:29:03 +0300 Subject: [PATCH] Add comment count to task list --- taskapp/locale/ru/LC_MESSAGES/django.po | 4 ++++ taskapp/templates/taskapp/tasklist.html | 3 ++- taskapp/templates/taskapp/tasklist_all.html | 3 ++- taskapp/views.py | 5 ++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/taskapp/locale/ru/LC_MESSAGES/django.po b/taskapp/locale/ru/LC_MESSAGES/django.po index 23dd5c5..acf2fd3 100644 --- a/taskapp/locale/ru/LC_MESSAGES/django.po +++ b/taskapp/locale/ru/LC_MESSAGES/django.po @@ -456,3 +456,7 @@ msgstr "Исполнители" msgid "Author does not specified" msgstr "Автор не указан" + +msgid "Name and comment count" +msgstr "Имя и количество комментов" + diff --git a/taskapp/templates/taskapp/tasklist.html b/taskapp/templates/taskapp/tasklist.html index 60b20e7..4171d95 100644 --- a/taskapp/templates/taskapp/tasklist.html +++ b/taskapp/templates/taskapp/tasklist.html @@ -7,7 +7,7 @@ - + @@ -40,6 +40,7 @@ {{ task.abon.get_full_name }} + {% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %}
{% trans 'Name' %}{% trans 'Name and comment count' %} {% trans 'Address' %} {% trans 'The nature of the damage' %} {% trans 'Description' %} {{ 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 @@ - + @@ -53,6 +53,7 @@ {{ task.abon.get_full_name }} + {% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %} 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
{% trans 'Name' %}{% trans 'Name and comment count' %} {% trans 'Address' %} {% trans 'The nature of the damage' %} {% trans 'Description' %} {{ task.abon.group.title }}, {{ task.abon.street|default:_('Not assigned') }} {{ task.abon.house|default:_('Not assigned') }}