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,
}
)
评论列表
文章目录