Showing categories with click count
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Apr 2013 11:22:28 +0000 (13:22 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 9 May 2013 09:03:22 +0000 (11:03 +0200)
questions/models.py
questions/templates/questions/question_list.html
questions/views.py

index b734346..746ad84 100644 (file)
@@ -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:
index 240fcf2..d9841a3 100755 (executable)
@@ -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.</p>
 
+Kategorie:
+{% for category in tag_categories %}
+    <p>{{category}} {{category.click_count}}</p>
+{% endfor %}
+
 Tematy: 
 {% if tag %}<a href=".">wszystkie</a>
 {% else %}<strong>wszystkie</strong>
index be955fb..6a2dc52 100644 (file)
@@ -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