From: Aleksander Łukasz Date: Thu, 25 Apr 2013 11:22:28 +0000 (+0200) Subject: Showing categories with click count X-Git-Url: https://git.mdrn.pl/prawokultury.git/commitdiff_plain/df056627e66bc0170290f7f57b7a8c59ac953458?ds=sidebyside Showing categories with click count --- diff --git a/questions/models.py b/questions/models.py index b734346..746ad84 100644 --- a/questions/models.py +++ b/questions/models.py @@ -18,7 +18,7 @@ class TagCategory(models.Model): class Meta: verbose_name = _("Tag Category") - verbose_name_plural = _("Tag Categries") + verbose_name_plural = _("Tag Categories") def __unicode__(self): return self.name @@ -31,7 +31,7 @@ class Tag(TagBase): slug += "_%d" % i return slug - category = models.ForeignKey(TagCategory, blank = True, null = True, on_delete = models.SET_NULL) + category = models.ForeignKey(TagCategory, blank = True, null = True, on_delete = models.SET_NULL, related_name = 'tags') click_count = models.IntegerField(null = False, default = 0) class Meta: diff --git a/questions/templates/questions/question_list.html b/questions/templates/questions/question_list.html index 240fcf2..d9841a3 100755 --- a/questions/templates/questions/question_list.html +++ b/questions/templates/questions/question_list.html @@ -27,6 +27,11 @@ autorem szeregu publikacji naukowych poświęconych korzystaniu z technologii informacyjno-komunikacyjnych oraz posiada wieloletnie doświadczenie doradcze w tej tematyce.

+Kategorie: +{% for category in tag_categories %} +

{{category}} {{category.click_count}}

+{% endfor %} + Tematy: {% if tag %}wszystkie {% else %}wszystkie diff --git a/questions/views.py b/questions/views.py index be955fb..6a2dc52 100644 --- a/questions/views.py +++ b/questions/views.py @@ -8,7 +8,7 @@ from django.shortcuts import get_object_or_404 from django.views.generic import ListView from django.views.generic.edit import FormView from .forms import QuestionForm -from .models import Question, Tag +from .models import Question, Tag, TagCategory class QuestionFormView(FormView): @@ -45,4 +45,5 @@ class QuestionListView(ListView): context['tags'] = Tag.objects.filter(items__question__published=True ).annotate(c=models.Count('items__tag')).order_by('-c', 'slug') context['tag'] = self.tag + context['tag_categories'] = TagCategory.objects.all().annotate(click_count = models.Sum('tags__click_count')) return context