def content_html(self): from blog.models import Post from comment.models import Comment result = '' if self.display_type == self.DISPLAY_HTML: result = self.content elif self.display_type == self.DISPLAY_LATEST: context = {'post': Post.all_posts()} result = render_to_string('sidebar_posts.html', context) elif self.display_type == self.DISPLAY_HOT: context = {'post': Post.hot_posts()} result = render_to_string('sidebar_posts.html', context) elif self.display_type == self.DISPLAY_COMMENT: context = { 'comments': Comment.objects.filter(status=Comment.STAUS_NORMAL) } result = render_to_string('sidebar_comments.html', context) return result