예제 #1
0
파일: models.py 프로젝트: Mark-Jordan/blog
    def content_html(self):
        """直接渲染模板"""
        from main.models import Post  # 避免循环引用
        from comment.models import Comment

        result=''
        show_items_num=5
        if self.display_type==self.DISPLAY_HTML:
            result=self.content
        elif self.display_type==self.DISPLAY_LATEST:
            context={
                'posts':Post.latest_posts()[:show_items_num]
            }
            tes=render_to_string('config/blocks/sidebar_posts.html',context=context)
            result=render_to_string('config/blocks/sidebar_posts.html',context=context)
        elif self.display_type==self.DISPLAY_HOT:
            context={
                'posts': Post.hot_posts()[:show_items_num],
            }
            result=render_to_string('config/blocks/sidebar_posts.html',context=context)
        elif self.display_type==self.DISPLAY_COMMENT:
            context={
                'comments': Comment.objects.filter(status=Comment.STATUS_NORMAL)[:show_items_num]
            }
            result=render_to_string('config/blocks/sidebar_comments.html',context=context)

        return result