update models

scl-branch
jisyoona 1 year ago
parent 3d8be360ef
commit f05d617dca

@ -1,5 +1,7 @@
from django.shortcuts import render
from django.http import JsonResponse
# Create your views here.

@ -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")),
]

@ -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"

@ -3,5 +3,6 @@ from django.urls import path
from Student.views import *
urlpatterns = [
path("", studnets)
path("", studnets),
path("delete", delete_student)
]

@ -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)

Loading…
Cancel
Save