From 8c99202755ff5875d33768117bb39deecf97c1f9 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 23 Jun 2021 11:20:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=80=BB=E6=8E=92=E5=90=8D?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- safesite/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/safesite/views.py b/safesite/views.py index 25d5db0f..41a6670f 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -21,7 +21,7 @@ from django.contrib.auth.hashers import check_password, make_password from django.contrib.sessions.models import Session from django.core import serializers from django.core.serializers.json import DjangoJSONEncoder -from django.db.models import Avg, Count, F, Q, Sum +from django.db.models import Avg, Count, F, Q, Sum, Max from django.forms.models import model_to_dict from django.http import (HttpResponse, HttpResponseRedirect, JsonResponse, request) @@ -6710,7 +6710,11 @@ def apiexamtestrate(req): companyid = req.GET.get('companyid') alltest = ExamTest.objects.filter(usecomps__contains=','+str(companyid)+',').exclude(nousecomps__contains=','+str(companyid)+',') allexamtestdetail = ExamTestDetail.objects.filter(examtest__in=alltest,testnum__gte=1) - objs = allexamtestdetail.values('user__userid','user__name','user__headimgurl','user__ubelongpart__partname').annotate(totalscore=Sum('score'),totaltook=Sum('took'),testnum=Count('user__userid')).order_by('-totalscore','totaltook') + objs = allexamtestdetail.values('user__userid','user__name','user__headimgurl','user__ubelongpart__partname').annotate(totalscore=Sum('score'),totaltook=Sum('took'),testnum=Count('user__userid'), maxscore = Max('score')) + # if req.GET.get('type', None) == 'max': + objs = objs.order_by('-maxscore','testnum', '-totalscore') + # else: + # objs = objs.order_by('-totalscore','totaltook') total = objs.count() objslist = list(objs) for i in objslist: