From f05d617dca1ed990396f864c936010b236afef30 Mon Sep 17 00:00:00 2001 From: jisyoona <664501563@qq.com> Date: Thu, 7 Sep 2023 10:54:46 +0800 Subject: [PATCH] update models --- EduSystemServer/API/views.py | 4 +++- EduSystemServer/EduSystemServer/urls.py | 2 +- EduSystemServer/Student/models.py | 16 ++++++++-------- EduSystemServer/Student/urls.py | 3 ++- EduSystemServer/Student/views.py | 25 +++++++++++++++---------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/EduSystemServer/API/views.py b/EduSystemServer/API/views.py index 0d36511..8bda5b8 100644 --- a/EduSystemServer/API/views.py +++ b/EduSystemServer/API/views.py @@ -1,7 +1,9 @@ from django.shortcuts import render from django.http import JsonResponse + + # Create your views here. def student(request): - return JsonResponse({"sid": 1, "sname":"张三"}) + return JsonResponse({"sid": 1, "sname": "张三"}) diff --git a/EduSystemServer/EduSystemServer/urls.py b/EduSystemServer/EduSystemServer/urls.py index 2b2d6da..ef87b34 100644 --- a/EduSystemServer/EduSystemServer/urls.py +++ b/EduSystemServer/EduSystemServer/urls.py @@ -20,5 +20,5 @@ from django.urls import path, include urlpatterns = [ path('Eduadmin/', admin.site.urls), path('api/', include(("API.urls", "api"), namespace="api")), - path('student/', include(("Student.urls", "studnet"), namespace="student")), + path('student/', include(("Student.urls", "student"), namespace="student")), ] diff --git a/EduSystemServer/Student/models.py b/EduSystemServer/Student/models.py index 48c8358..daa5a52 100644 --- a/EduSystemServer/Student/models.py +++ b/EduSystemServer/Student/models.py @@ -4,17 +4,17 @@ from django.db import models # Create your models here. class Student(models.Model): sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid") - username = models.CharField(max_length=30, verbose_name="用户名称", name="s_username", blank=True) - password = models.CharField(max_length=100, verbose_name="密码", name="s_password", blank=True) + s_username = models.CharField(max_length=30, verbose_name="用户名称", name="s_username", blank=True) + s_password = models.CharField(max_length=100, verbose_name="密码", name="s_password", blank=True) s_name = models.CharField(max_length=100, verbose_name="姓名", name="s_name", blank=True) - sex = models.CharField(max_length=4, verbose_name="性别", name="s_sex", blank=True) - grade = models.CharField(max_length=20, verbose_name="年级", name="s_grade", blank=True) - class_name = models.CharField(max_length=50, verbose_name="班级", name="s_class_name", blank=True) - major = models.CharField(max_length=50, verbose_name="专业名称", name="s_major", blank=True) + s_sex = models.CharField(max_length=4, verbose_name="性别", name="s_sex", blank=True) + s_grade = models.CharField(max_length=20, verbose_name="年级", name="s_grade", blank=True) + s_class_name = models.CharField(max_length=50, verbose_name="班级", name="s_class_name", blank=True) + s_major = models.CharField(max_length=50, verbose_name="专业名称", name="s_major", blank=True) def to_dict(self): - return {"sid": self.sid, "s_name": self.s_name, "username": self.username, "password": self.password, - "s_sex": self.sex, "s_grade": self.grade, "class_name": self.class_name, "major": self.major} + return {"sid": self.sid, "s_name": self.s_name, "s_username": self.s_username, "s_password": self.s_password, + "s_sex": self.s_sex, "s_grade": self.s_grade, "s_class_name": self.s_class_name, "s_major": self.s_major} class Meta: db_table = "student" diff --git a/EduSystemServer/Student/urls.py b/EduSystemServer/Student/urls.py index 78f4a6b..bbefd5c 100644 --- a/EduSystemServer/Student/urls.py +++ b/EduSystemServer/Student/urls.py @@ -3,5 +3,6 @@ from django.urls import path from Student.views import * urlpatterns = [ - path("", studnets) + path("", studnets), + path("delete", delete_student) ] \ No newline at end of file diff --git a/EduSystemServer/Student/views.py b/EduSystemServer/Student/views.py index d33cf19..fae5fc7 100644 --- a/EduSystemServer/Student/views.py +++ b/EduSystemServer/Student/views.py @@ -4,21 +4,27 @@ from django.shortcuts import render from django.http import JsonResponse from Student.models import Student from django.views.decorators.csrf import csrf_exempt +from django.http import QueryDict + + +def delete_student(request): + sid = request.GET.get("sid") + info = Student.objects.filter(sid=sid).delete() + response = {"code": 200, "message": "删除成功!", "data": info} + return JsonResponse(response) + @csrf_exempt def studnets(request): if request.method == "POST": student = Student() - student.username = request.POST.get("username") - student.password = request.POST.get("password") + student.s_username = request.POST.get("s_username") + student.s_password = request.POST.get("s_password") student.s_name = request.POST.get("s_name") - student.sex = request.POST.get("sex") - student.grade = int(request.POST.get("grade")) - print(student.grade) - student.class_name = request.POST.get("class_name") - student.major = request.POST.get("major") - student.sid = request.POST.get("sid") - print(student.to_dict()) + student.s_sex = request.POST.get("s_sex") + student.s_grade = request.POST.get("s_grade") + student.s_class_name = request.POST.get("s_class_name") + student.s_major = request.POST.get("s_major") student.save() response = {"code": 200, "message": "添加成功!", "data": student.to_dict()} return JsonResponse(response) @@ -29,4 +35,3 @@ def studnets(request): response_json["data"].append(student.to_dict()) return JsonResponse(response_json) -