Further improvement of teacher functions

-Query student information
lrs-branch
lrs 1 year ago
parent 1fa138dd24
commit 7bc09e1bc6

@ -303,6 +303,31 @@ def course_selection(request):
except IntegrityError:
response = ResponseUtil.error("插入数据失败tid_id 列不能为 null")
return JsonResponse(response)
if request.method == 'GET':
cid = request.GET.get('cid')
name = request.GET.get('name')
type = request.GET.get('type')
credit = request.GET.get('credit')
tid = request.GET.get('tid')
# 定义空查询条件
conditions = Q()
if cid:
conditions &= Q(cid=cid)
if name:
conditions &= Q(name=name)
if type:
conditions &= Q(type=type)
if credit:
conditions &= Q(credit=credit)
if tid:
conditions &= Q(tid=tid)
# 添加非空查询条件至基本查询集
query = Course.objects.filter(conditions)
data = query.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
print(query)
response = ResponseUtil.ok(data, "课程信息查询成功")
return JsonResponse(response)
if request.method == 'DELETE':
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
posdict = parser.parse()

Loading…
Cancel
Save