Предварительная сохраняшка
This commit is contained in:
1 parent
ba33de3d77
commit
17f35a0f5d
875 files changed
+146196
-124
No files matched your search
@@ -0,0 +1,38 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.generics import ListAPIView
|
||||
from .models import *
|
||||
from rest_framework.permissions import AllowAny, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from django.views.generic import ListView
|
||||
from .serializers import *
|
||||
from datetime import date
|
||||
from django.db.models import Sum
|
||||
|
||||
# Create your views here.
|
||||
|
||||
class Counter(ListAPIView):
|
||||
permission_classes = (AllowAny,)
|
||||
serializer_class = CountSerializer
|
||||
|
||||
# def get(self, request):
|
||||
# qs = CountVisitor.objects.values()
|
||||
# return Response(qs)
|
||||
|
||||
def post(self, request):
|
||||
print(request.data['user__id'])
|
||||
if request.data['user__id'] is not None:
|
||||
# print("sdddddd")
|
||||
watch,create = CountVisitor.objects.get_or_create(user = User(id=request.data['user__id']),page=request.data['page'], visitdate=date.today())
|
||||
|
||||
else:
|
||||
watch,create = CountVisitor.objects.get_or_create(user__id__isnull=True, page=request.data['page'], visitdate=date.today())
|
||||
watch.count+=1
|
||||
watch.save()
|
||||
|
||||
res = {"totalvisit": CountVisitor.objects.aggregate(Sum('count'))['count__sum'],
|
||||
"visittoday":CountVisitor.objects.filter(visitdate=date.today()).aggregate(Sum('count'))['count__sum'],
|
||||
"uniqtoday" : CountVisitor.objects.filter(visitdate=date.today()).count()
|
||||
|
||||
}
|
||||
return Response(res)
|
||||
|
||||
Reference in new issue
Block a user