天天看點

資料統計之使用者總量統計資料統計

資料統計

資料統計之使用者總量統計資料統計

在進入到背景頁面後,首先我們需要完成如下功能:

1、使用者總數統計

2、日增使用者統計

3、日活使用者統計

4、下單使用者統計

5、月新增使用者統計

6、商品通路量統計

【将所有的業務邏輯的代碼都放在meiduo_admin/views檔案中,建立statistical.py】

1.使用者總量統計

接口分析

請求方式: GET 

/meiduo_admin/statistical/total_count/

請求參數: 通過請求頭傳遞jwt token資料。

傳回資料: JSON

{
        "count": "總使用者量",
        "date": "日期"
}
           
傳回值 類型 是否必須 說明
count int 總使用者量
date date 日期

資料統計之使用者總量統計資料統計

 後端實作

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 UserTotalCountView(APIView):
    # 指定管理者權限
    permission_classes = [IsAdminUser]

    def get(self,request):
        # 擷取目前日期
        now_date=date.today()
        # 擷取所有使用者總數
        count= User.objects.all().count()
        return Response({
            'count':count,
            'date':now_date
        })
           

postman測試:

資料統計之使用者總量統計資料統計
資料統計之使用者總量統計資料統計
資料統計之使用者總量統計資料統計