日活跃用户统计
接口分析
请求方式:GET /meiduo_admin/statistical/day_active/
# 日活跃用户统计
url(r'^statistical/day_active/$', statistical.UserActiveCountView.as_view()),
请求参数: 通过请求头传递jwt token数据。
返回数据: JSON
{
"count": "活跃用户量",
"date": "日期"
}
返回值类型是否必须说明countint是活跃用户量datedate是日期
后端实现
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAdminUser
from datetime import date
from users.models import User
class UserActiveCountView(APIView):
# 指定管理员权限
permission_classes = [IsAdminUser]
def get(self,request):
# 获取当前日期
now_date=date.today()
# 获取当日登录用户数量 last_login记录最后登录时间
count=User.objects.filter(last_login__gte=now_date).count()
return Response({
"count":count,
"date" : now_date
})
postman测试: