Further improvement of teacher functions

-Query student information
lrs-branch
lrs 1 year ago
parent d2b971806f
commit fd5e26b71a

@ -14,4 +14,5 @@ urlpatterns = [
path('delete/',delete), path('delete/',delete),
path('student/',student_performance_management), path('student/',student_performance_management),
path('query/',query_student_information), path('query/',query_student_information),
path('course/',teaching_resources)
] ]

@ -97,39 +97,39 @@ def delete(request):
@csrf_exempt @csrf_exempt
def teaching_resources(request): def teaching_resources(request):
if request.method == 'POST': if request.method == 'POST':
cid = request.POST.get('cid')
name = request.POST.get('name') name = request.POST.get('name')
sid = request.POST.get('sid') type = request.POST.get('type')
sex = request.POST.get('sex') credit = request.POST.get('credit')
grade = request.POST.get('grade') tid = request.POST.get('tid')
class_name = request.POST.get('class_name') t_name = request.POST.get('t_name')
major = request.POST.get('major')
# 定义空查询条件 # 定义空查询条件
conditions = Q() conditions = Q()
t_conditions = Q()
if cid:
conditions &= Q(cid=cid)
if name: if name:
conditions &= Q(name=name) conditions &= Q(name=name)
if sid: if type:
conditions &= Q(sid=sid) conditions &= Q(type=type)
if sex: if credit:
conditions &= Q(sex=sex) conditions &= Q(credit=credit)
if grade: if tid:
conditions &= Q(grade=grade) t_conditions &= Q(tid=tid)
if class_name: if t_name:
conditions &= Q(class_name=class_name) t_conditions &= Q(t_name=t_name)
if major:
conditions &= Q(major=major)
# 添加非空查询条件至基本查询集 # 添加非空查询条件至基本查询集
query = Student.objects.filter(conditions) query1 = Course.objects.filter(conditions)
data = query.values() # 将 QuerySet 对象转换为字典列表 query2 = Teacher.objects.filter(t_conditions)
data = list(data) # 转换为列表以便序列化为 JSON combined_data = []
print(query) for item in query2:
response = ResponseUtil.ok(data, "课程信息查询成功") matching_items = query1.filter(tid=item.tid).values()
combined_data.extend(matching_items)
print(combined_data)
response = ResponseUtil.ok("课程信息查询成功")
return JsonResponse(response) return JsonResponse(response)
elif request.method == "GET": elif request.method == "GET":
query = Student.objects.all() pass
data = query.values() # 将 QuerySet 对象转换为字典列表
data = list(data) # 转换为列表以便序列化为 JSON
response = ResponseUtil.ok(data, "课程信息查询成功")
return JsonResponse(response)
@csrf_exempt @csrf_exempt
def query_student_information(request): def query_student_information(request):

Loading…
Cancel
Save