feat: exam/view 随机生成试题后 并进行排序
This commit is contained in:
parent
ac8c44507a
commit
9aa0954e99
|
@ -29,6 +29,8 @@ import shutil
|
|||
from django.db.models import Q
|
||||
from django.core.cache import cache
|
||||
import uuid
|
||||
from itertools import chain # 用于合并多个列表
|
||||
|
||||
# Create your views here.
|
||||
|
||||
EXCEL_PATH = os.path.join(settings.BASE_DIR, "media/default/question.xlsx")
|
||||
|
@ -284,6 +286,14 @@ class PaperViewSet(ModelViewSet):
|
|||
return PaperCreateUpdateSerializer
|
||||
return super().get_serializer_class()
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
"""
|
||||
重写destroy方法实现真删除
|
||||
"""
|
||||
instance = self.get_object() # 获取要删除的对象
|
||||
instance.delete() # 调用模型的 delete 方法,进行真删除
|
||||
return Response({"detail": "删除成功"}, status=204)
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
sr = PaperCreateUpdateSerializer(data=request.data)
|
||||
sr.is_valid(raise_exception=True)
|
||||
|
@ -572,8 +582,9 @@ class ExamViewSet(CreateUpdateCustomMixin, ModelViewSet):
|
|||
single_qs = Question.objects.filter(Q(type="单选") & Q(questioncat__in=cqs)).order_by('?')[:exam.paper.danxuan_count]
|
||||
multiple_qs = Question.objects.filter(Q(type="多选") & Q(questioncat__in=cqs)).order_by('?')[:exam.paper.duoxuan_count]
|
||||
judge_qs = Question.objects.filter(Q(type="判断") & Q(questioncat__in=cqs)).order_by('?')[:exam.paper.panduan_count]
|
||||
pqs = single_qs | multiple_qs | judge_qs
|
||||
for i in pqs:
|
||||
# 按照单选、多选、判断的顺序合并题目
|
||||
sorted_questions = chain(single_qs, multiple_qs, judge_qs) # 顺序合并为一个迭代器
|
||||
for i in sorted_questions:
|
||||
if i.type == '单选':
|
||||
total_score = exam.paper.danxuan_score
|
||||
elif i.type == '多选':
|
||||
|
|
Loading…
Reference in New Issue