From 8e668ac27f54b33b97ff05558b79934d731a3d63 Mon Sep 17 00:00:00 2001 From: sonicaks Date: Mon, 14 Oct 2019 17:38:58 +0530 Subject: [PATCH 1/2] Add feature: count attribute on tags --- app/templates/tags.html | 2 +- app/views.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/templates/tags.html b/app/templates/tags.html index 142bba2..0c32fe9 100644 --- a/app/templates/tags.html +++ b/app/templates/tags.html @@ -7,7 +7,7 @@

Tags

{% if tags %} {% for tag in tags %} - 📌 {{ tag.name }} + 📌 {{ tag.tags__name }} {{ tag.count }}   {% endfor %} {% endif %} diff --git a/app/views.py b/app/views.py index 274e3ce..627a1a3 100644 --- a/app/views.py +++ b/app/views.py @@ -1,7 +1,7 @@ import time from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator -from django.db.models import Q +from django.db.models import Q, Count from django.shortcuts import render from django.views.generic import TemplateView from taggie.parser import generate_tags @@ -73,7 +73,8 @@ def latest(request): def tags(request): """view for the tags""" - tags = Tag.objects.all() + tags = Tutorial.objects.values('tags__name').annotate(count = Count('tags')) + context = { 'tags': tags, 'title': 'Tags' From fb97c71f9de6b7e620f51db7d2b964e28a17a97e Mon Sep 17 00:00:00 2001 From: sonicaks Date: Tue, 15 Oct 2019 21:20:43 +0530 Subject: [PATCH 2/2] Add filter for published tutorials --- app/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views.py b/app/views.py index 627a1a3..1d1bd80 100644 --- a/app/views.py +++ b/app/views.py @@ -73,7 +73,7 @@ def latest(request): def tags(request): """view for the tags""" - tags = Tutorial.objects.values('tags__name').annotate(count = Count('tags')) + tags = Tutorial.objects.filter(publish=True).values('tags__name').annotate(count=Count('tags')) context = { 'tags': tags,