diff --git a/blog/models.py b/blog/models.py index 4784562..80b3515 100644 --- a/blog/models.py +++ b/blog/models.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- from django.db import models from django.utils import timezone @@ -23,14 +23,16 @@ class Post(models.Model): def __unicode__(self): return self.title - + def font_size(self): min_font = 12 max_font = 28 v = Tag.objects.all().annotate(c = Count('post')).filter(c__gt = 0).aggregate(Min('c'), Max('c')) max_tag, min_tag = v["c__max"], v["c__min"] - step = (max_font - min_font)/float(max_tag-min_tag) + + try: step = (max_font - min_font)/float(max_tag-min_tag) + except: step = 1 tag_count = Post.objects.filter(tags__name=self.name).count() #print Tag.objects.filter(name=self.name).annotate(c = Count('post')) font = int(min_font + (tag_count-min_tag)*step)