views.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:bbgo 作者: genonfire 项目源码 文件源码
def dashboard(request, condition='recent'):
    """Dashboard"""
    post_count = settings.DASHBOARD_POST_COUNT
    comment_count = settings.DASHBOARD_COMMENT_COUNT

    if condition == 'recent':
        order = '-id'
    elif condition == 'view':
        order = '-view_count'
    elif condition == 'like':
        order = '-like_count'
    elif condition == 'comment':
        order = '-comment_count'
    else:
        return error_page(request)

    posts = Blog.objects.filter(status='1normal').order_by(order)[:post_count]
    comments = Comment.objects.filter(
        status='1normal').order_by('-id')[:comment_count]

    total_posts = Blog.objects.filter(status='1normal').count()
    total_comments = Comment.objects.filter(status='1normal').count()
    total_spams = Comment.objects.filter(status='7spam').count()
    total_users = User.objects.count()

    return render(
        request,
        "blogs/dashboard.html",
        {
            'posts': posts,
            'comments': comments,
            'condition': condition,
            'total_posts': total_posts,
            'total_comments': total_comments,
            'total_spams': total_spams,
            'total_users': total_users,
        }
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号