updata models

scl-branch
jisyoona 1 year ago
parent ad8e8b58d9
commit a695911d1b

@ -1,8 +1,10 @@
from django.shortcuts import render from django.shortcuts import render
# Create your views here. # Create your views here.
from django.http import HttpRequest
from django.http import JsonResponse from django.http import JsonResponse
from EduSystemServer.utils import ResponseUtil from EduSystemServer.utils import ResponseUtil
from .models import Student from .models import Student
from course.models import SC, Course
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.http import QueryDict from django.http import QueryDict
from io import BytesIO from io import BytesIO
@ -63,8 +65,8 @@ def studnets(request):
data.append(student.to_dict()) data.append(student.to_dict())
else: else:
all_objects = Student.objects.all() all_objects = Student.objects.all()
for studnet in all_objects: for student in all_objects:
data.append(studnet.to_dict()) data.append(student.to_dict())
response = ResponseUtil.ok(data, "查询成功!") response = ResponseUtil.ok(data, "查询成功!")
return JsonResponse(response) return JsonResponse(response)
elif request.method == "DELETE": elif request.method == "DELETE":
@ -87,18 +89,33 @@ def studnets(request):
grade = put[0]['grade'] grade = put[0]['grade']
class_name = put[0]['class_name'] class_name = put[0]['class_name']
major = put[0]['major'] major = put[0]['major']
try: if Student.objects.filter(sid=sid):
Student.objects.filter(sid=sid).update(username=username, name=name, sex=sex, grade=grade, Student.objects.filter(sid=sid).update(username=username, name=name, sex=sex, grade=grade,
class_name=class_name, class_name=class_name,
major=major) major=major)
except: else:
Student.objects.create(sid=sid, username=username, name=name, sex=sex, grade=grade, return JsonResponse(ResponseUtil.error("没有查询到该同学!"))
class_name=class_name,
major=major)
data = Student.objects.filter(sid=sid)[0].to_dict() data = Student.objects.filter(sid=sid)[0].to_dict()
return JsonResponse(ResponseUtil.ok(data, "修改成功!")) return JsonResponse(ResponseUtil.ok(data, "修改成功!"))
def get_select_course_by_id(request): def search_grade(request):
if request.method == "GET":
sid = request.GET.get('sid')
cid = SC.objects.filter(sid_id=sid).values()
data_list = []
for i in range(len(cid)):
c_name = Course.objects.filter(cid=cid[i]['cid_id']).values('name')[0]['name']
middle_grade = cid[i]['middle_grade']
end_grade = cid[i]['end_grade']
data = {
'c_name': c_name,
'平时成绩': middle_grade,
'最终成绩': end_grade
}
data_list.append(data)
return JsonResponse(ResponseUtil.ok(data_list, "成绩查询成功!"))
def get_select_course_by_id(request):
pass pass

Loading…
Cancel
Save