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):
).order_by('-published_at')
if self.tag:
qs = qs.filter(tags=self.tag)
+ self.tag.click_count += 1
+ self.tag.save()
return qs
def get_context_data(self, *args, **kwargs):
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