diff --git a/EduSystemServer/teacher/urls.py b/EduSystemServer/teacher/urls.py index 93b00b7..bd8a6ee 100644 --- a/EduSystemServer/teacher/urls.py +++ b/EduSystemServer/teacher/urls.py @@ -14,4 +14,5 @@ urlpatterns = [ path('delete/',delete), path('student/',student_performance_management), path('query/',query_student_information), + path('course/',teaching_resources) ] \ No newline at end of file diff --git a/EduSystemServer/teacher/views.py b/EduSystemServer/teacher/views.py index 988ac62..b7c81d7 100644 --- a/EduSystemServer/teacher/views.py +++ b/EduSystemServer/teacher/views.py @@ -97,39 +97,39 @@ def delete(request): @csrf_exempt def teaching_resources(request): if request.method == 'POST': + cid = request.POST.get('cid') name = request.POST.get('name') - sid = request.POST.get('sid') - sex = request.POST.get('sex') - grade = request.POST.get('grade') - class_name = request.POST.get('class_name') - major = request.POST.get('major') + type = request.POST.get('type') + credit = request.POST.get('credit') + tid = request.POST.get('tid') + t_name = request.POST.get('t_name') # 定义空查询条件 conditions = Q() + t_conditions = Q() + if cid: + conditions &= Q(cid=cid) if name: conditions &= Q(name=name) - if sid: - conditions &= Q(sid=sid) - if sex: - conditions &= Q(sex=sex) - if grade: - conditions &= Q(grade=grade) - if class_name: - conditions &= Q(class_name=class_name) - if major: - conditions &= Q(major=major) + if type: + conditions &= Q(type=type) + if credit: + conditions &= Q(credit=credit) + if tid: + t_conditions &= Q(tid=tid) + if t_name: + t_conditions &= Q(t_name=t_name) # 添加非空查询条件至基本查询集 - query = Student.objects.filter(conditions) - data = query.values() # 将 QuerySet 对象转换为字典列表 - data = list(data) # 转换为列表以便序列化为 JSON - print(query) - response = ResponseUtil.ok(data, "课程信息查询成功") + query1 = Course.objects.filter(conditions) + query2 = Teacher.objects.filter(t_conditions) + combined_data = [] + for item in query2: + matching_items = query1.filter(tid=item.tid).values() + combined_data.extend(matching_items) + print(combined_data) + response = ResponseUtil.ok("课程信息查询成功") return JsonResponse(response) elif request.method == "GET": - query = Student.objects.all() - data = query.values() # 将 QuerySet 对象转换为字典列表 - data = list(data) # 转换为列表以便序列化为 JSON - response = ResponseUtil.ok(data, "课程信息查询成功") - return JsonResponse(response) + pass @csrf_exempt def query_student_information(request):