You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
763 B

#coding=utf-8
from django.db.models import Count
from post.models import Post
def getRightInfo(request):
#1.获取分类信息
r_catepost = Post.objects.values('category__cname','category').annotate(c=Count('*')).order_by('-c')
#2.近期文章
r_recpost = Post.objects.all().order_by('-created')[:3]
#3.获取日期归档信息 原生查询
from django.db import connection
cursor = connection.cursor()
cursor.execute("select created,count('*') c from t_post GROUP BY DATE_FORMAT(created,'%Y-%m') ORDER BY c desc,created desc")
# 获取查询结果
r_filepost = cursor.fetchall()
# 返回获取的标签信息以字典的形式
return {'r_catepost':r_catepost,'r_recpost':r_recpost,'r_filepost':r_filepost}