diff --git a/.idea/EduSystem.iml b/.idea/EduSystem.iml
index 8388dbc..9710855 100644
--- a/.idea/EduSystem.iml
+++ b/.idea/EduSystem.iml
@@ -2,7 +2,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/deployment.xml b/.idea/deployment.xml
new file mode 100644
index 0000000..6300278
--- /dev/null
+++ b/.idea/deployment.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d56657a..65531ca 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/EduSystemServer/EduSystemServer/urls.py b/EduSystemServer/EduSystemServer/urls.py
index 2b2d6da..7f7d64d 100644
--- a/EduSystemServer/EduSystemServer/urls.py
+++ b/EduSystemServer/EduSystemServer/urls.py
@@ -17,8 +17,10 @@ from django.contrib import admin
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('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")),
]
diff --git a/EduSystemServer/Student/models.py b/EduSystemServer/Student/models.py
index 48c8358..0b690ff 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, "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..df57970 100644
--- a/EduSystemServer/Student/urls.py
+++ b/EduSystemServer/Student/urls.py
@@ -1,6 +1,6 @@
from django.urls import path
-from Student.views import *
+from .views import *
urlpatterns = [
path("", studnets)
diff --git a/EduSystemServer/Student/views.py b/EduSystemServer/Student/views.py
index d33cf19..7642c73 100644
--- a/EduSystemServer/Student/views.py
+++ b/EduSystemServer/Student/views.py
@@ -2,22 +2,23 @@ from django.shortcuts import render
# Create your views here.
from django.http import JsonResponse
-from Student.models import Student
+from .models import Student
from django.views.decorators.csrf import csrf_exempt
-
+from django.http import QueryDict
@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")
+ 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")
+
+ print(student.sid)
print(student.to_dict())
student.save()
response = {"code": 200, "message": "添加成功!", "data": student.to_dict()}
@@ -28,5 +29,11 @@ def studnets(request):
for student in student_list:
response_json["data"].append(student.to_dict())
return JsonResponse(response_json)
-
+ elif request.method == 'DELETE':
+ params = QueryDict(request.body)
+ key = next(iter(params.keys())) # 获取键名
+ value = params.get(key) # 获取值
+ xx = str(value).split('-')[0]
+ print(xx.split('\r\n'))
+ return JsonResponse({'code': 200, 'msg': 'success'}, safe=False)
diff --git a/EduSystemServer/teacher/models.py b/EduSystemServer/teacher/models.py
index d6ce4c4..c20314f 100644
--- a/EduSystemServer/teacher/models.py
+++ b/EduSystemServer/teacher/models.py
@@ -5,11 +5,14 @@ from django.db import models
class Teacher(models.Model):
tid = models.AutoField(primary_key=True, verbose_name="教师编号", name="tid")
t_name = models.CharField(max_length=255, verbose_name="教师名称", name="t_name", blank=True)
- sex = models.CharField(max_length=128, verbose_name="教师性别", name="t_sex", blank=True)
- title = models.CharField(max_length=128, verbose_name="教师职称", name="t_title", blank=True)
- education = models.CharField(max_length=128, verbose_name="教师学历", name="t_education", blank=True)
- dept = models.CharField(max_length=128, verbose_name="教师所属院系", name="t_dept", blank=True)
+ t_sex = models.CharField(max_length=128, verbose_name="教师性别", name="t_sex", blank=True)
+ t_title = models.CharField(max_length=128, verbose_name="教师职称", name="t_title", blank=True)
+ t_education = models.CharField(max_length=128, verbose_name="教师学历", name="t_education", blank=True)
+ t_dept = models.CharField(max_length=128, verbose_name="教师所属院系", name="t_dept", blank=True)
+ def to_dict(self):
+ return {"tid": self.tid, "t_name": self.t_name, "t_sex": self.t_sex, "t_title": self.t_title,
+ "t_education": self.t_education, "t_dept": self.t_dept}
class Meta:
db_table = "teacher"
verbose_name = "教师"
diff --git a/EduSystemServer/teacher/urls.py b/EduSystemServer/teacher/urls.py
new file mode 100644
index 0000000..ff48d6b
--- /dev/null
+++ b/EduSystemServer/teacher/urls.py
@@ -0,0 +1,14 @@
+# -*- coding: utf-8 -*-
+# Time : 2023/9/7 10:54
+# Author : lirunsheng
+# User : l'r's
+# Software: PyCharm
+# File : urls.py
+
+from django.urls import path
+
+from .views import *
+
+urlpatterns = [
+ path("", teacher)
+]
\ No newline at end of file
diff --git a/EduSystemServer/teacher/views.py b/EduSystemServer/teacher/views.py
index 91ea44a..07e747c 100644
--- a/EduSystemServer/teacher/views.py
+++ b/EduSystemServer/teacher/views.py
@@ -1,3 +1,54 @@
from django.shortcuts import render
# Create your views here.
+
+# Create your views here.
+from django.http import JsonResponse
+from .models import Teacher
+from django.views.decorators.csrf import csrf_exempt
+from django.http import QueryDict
+@csrf_exempt
+def teacher(request):
+ if request.method == "POST":
+ teacher_information = Teacher()
+ teacher_information.t_name = request.POST.get('t_name')
+ teacher_information.t_sex = request.POST.get('t_sex')
+ teacher_information.t_title = request.POST.get('t_title')
+ teacher_information.t_education = request.POST.get('t_education')
+ teacher_information.t_dept = request.POST.get('t_dept')
+ teacher_information.save()
+ print(teacher_information.t_name)
+ return JsonResponse({'code': 200, 'msg': 'success',"data": teacher_information.to_dict()}, safe=False)
+
+ elif request.method == "GET":
+ t_name = request.GET.get('t_name')
+ t_sex = request.GET.get('t_sex')
+ t_title = request.GET.get('t_title')
+ t_education = request.GET.get('t_education')
+ t_dept = request.GET.get('t_dept')
+ data = []
+ if t_name:
+ filtered = Teacher.objects.filter(t_name=t_name)
+ for teacher_x in filtered:
+ data.append(teacher_x.to_dict())
+ elif t_sex:
+ filtered = Teacher.objects.filter(t_sex=t_sex)
+ for teacher_x in filtered:
+ data.append(teacher_x.to_dict())
+ elif t_title:
+ filtered = Teacher.objects.filter(t_title=t_title)
+ for teacher_x in filtered:
+ data.append(teacher_x.to_dict())
+ elif t_education:
+ filtered = Teacher.objects.filter(t_education=t_education)
+ for teacher_x in filtered:
+ data.append(teacher_x.to_dict())
+ elif t_dept:
+ filtered = Teacher.objects.filter(t_dept=t_dept)
+ for teacher_x in filtered:
+ data.append(teacher_x.to_dict())
+ else:
+ all_objects = Teacher.objects.all()
+ for teacher_x in all_objects:
+ data.append(teacher_x.to_dict())
+ return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
\ No newline at end of file