From ad8e8b58d99cd19d7c561c4fbe5e82e46954a84a Mon Sep 17 00:00:00 2001
From: jisyoona <664501563@qq.com>
Date: Fri, 8 Sep 2023 11:26:23 +0800
Subject: [PATCH] updata models
---
.idea/misc.xml | 2 +-
EduSystemServer/.idea/EduSystemServer.iml | 16 +---
EduSystemServer/.idea/dataSources.xml | 13 +--
EduSystemServer/.idea/misc.xml | 16 +---
EduSystemServer/EduSystemServer/settings.py | 13 +--
EduSystemServer/EduSystemServer/urls.py | 17 +---
.../migrations/0002_auto_20230907_0916.py | 14 +--
EduSystemServer/Student/models.py | 35 -------
EduSystemServer/Student/views.py | 91 ++++++++-----------
.../migrations/0002_auto_20230907_0859.py | 4 +-
EduSystemServer/course/models.py | 2 +-
.../migrations/0002_auto_20230907_0859.py | 10 +-
12 files changed, 60 insertions(+), 173 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 65531ca..d56657a 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/EduSystemServer/.idea/EduSystemServer.iml b/EduSystemServer/.idea/EduSystemServer.iml
index d4543f0..258a1c1 100644
--- a/EduSystemServer/.idea/EduSystemServer.iml
+++ b/EduSystemServer/.idea/EduSystemServer.iml
@@ -14,21 +14,7 @@
-<<<<<<< Updated upstream
-=======
-<<<<<<< Updated upstream
->>>>>>> Stashed changes
-<<<<<<< HEAD
-
-=======
-
->>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa
-<<<<<<< Updated upstream
-=======
-=======
-
->>>>>>> Stashed changes
->>>>>>> Stashed changes
+
diff --git a/EduSystemServer/.idea/dataSources.xml b/EduSystemServer/.idea/dataSources.xml
index a5ca85d..490c74a 100644
--- a/EduSystemServer/.idea/dataSources.xml
+++ b/EduSystemServer/.idea/dataSources.xml
@@ -1,20 +1,11 @@
-
+
mysql.8
true
com.mysql.cj.jdbc.Driver
- jdbc:mysql://localhost:3306/edu_sys
- $ProjectFileDir$
-
-
- mysql.8
- true
- true
- $PROJECT_DIR$/EduSystemServer/settings.py
- com.mysql.cj.jdbc.Driver
- jdbc:mysql://127.0.0.1:3306/edu_sys
+ jdbc:mysql://localhost:3306
$ProjectFileDir$
diff --git a/EduSystemServer/.idea/misc.xml b/EduSystemServer/.idea/misc.xml
index 37f93ff..d56657a 100644
--- a/EduSystemServer/.idea/misc.xml
+++ b/EduSystemServer/.idea/misc.xml
@@ -1,18 +1,4 @@
-<<<<<<< Updated upstream
-=======
-<<<<<<< Updated upstream
->>>>>>> Stashed changes
-<<<<<<< HEAD
-
-=======
-
->>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa
-<<<<<<< Updated upstream
-=======
-=======
-
->>>>>>> Stashed changes
->>>>>>> Stashed changes
+
\ No newline at end of file
diff --git a/EduSystemServer/EduSystemServer/settings.py b/EduSystemServer/EduSystemServer/settings.py
index b34a3d0..85a4f98 100644
--- a/EduSystemServer/EduSystemServer/settings.py
+++ b/EduSystemServer/EduSystemServer/settings.py
@@ -12,9 +12,7 @@ https://docs.djangoproject.com/en/2.2/ref/settings/
import os
-<<<<<<< Updated upstream
-=======
CORS_ALLOW_ORIGIN_WHITELIST = [
"http://localhost:8080", # 允许访问的来源
"http://localhost:8000", # 允许访问的来源
@@ -22,7 +20,7 @@ CORS_ALLOW_ORIGIN_WHITELIST = [
]
CORS_ALLOW_CREDENTIALS = True # 允许跨域请求携带凭据(例如Cookies)
->>>>>>> Stashed changes
+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -65,7 +63,7 @@ MIDDLEWARE = [
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
-<<<<<<< Updated upstream
+
'django.middleware.common.CommonMiddleware',
# 'API.middle.AuthMiddleware',
]
@@ -86,13 +84,6 @@ CORS_ALLOW_HEADERS = (
'Pragma',
)
-
-=======
- # 'API.middle.AuthMiddleware',
-]
-
->>>>>>> Stashed changes
-
ROOT_URLCONF = 'EduSystemServer.urls'
TEMPLATES = [
diff --git a/EduSystemServer/EduSystemServer/urls.py b/EduSystemServer/EduSystemServer/urls.py
index 7cfa7f1..9cdcd26 100644
--- a/EduSystemServer/EduSystemServer/urls.py
+++ b/EduSystemServer/EduSystemServer/urls.py
@@ -16,26 +16,13 @@ Including another URLconf
from django.contrib import admin
from django.urls import path, include
from API.views import login, get_user_info
-<<<<<<< Updated upstream
-
-=======
->>>>>>> Stashed changes
-
-
urlpatterns = [
path('Eduadmin/', admin.site.urls),
- path('api/', include(("API.urls", "api"), namespace="api")),
-<<<<<<< Updated upstream
-=======
-<<<<<<< Updated upstream
->>>>>>> Stashed changes
+ path('api/', include(("API.urls", "API"), namespace="api")),
path('teacher/', include(("teacher.urls", "teacher"), namespace="teacher")),
- path('student/', include(("Student.urls", "student"), namespace="student")),
+ path('student/', include(("Student.urls", "Student"), namespace="student")),
path('course/', include(("course.urls", "course"), namespace="course")),
-=======
- path('student/', include(("Student.urls", "studnet"), namespace="student")),
->>>>>>> Stashed changes
path('login', login),
path('userinfo', get_user_info),
]
diff --git a/EduSystemServer/Student/migrations/0002_auto_20230907_0916.py b/EduSystemServer/Student/migrations/0002_auto_20230907_0916.py
index f8f5cfc..de1a609 100644
--- a/EduSystemServer/Student/migrations/0002_auto_20230907_0916.py
+++ b/EduSystemServer/Student/migrations/0002_auto_20230907_0916.py
@@ -12,37 +12,37 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='student',
- name='s_class_name',
+ name='class_name',
field=models.CharField(blank=True, max_length=50, verbose_name='班级'),
),
migrations.AlterField(
model_name='student',
- name='s_grade',
+ name='grade',
field=models.CharField(blank=True, max_length=20, verbose_name='年级'),
),
migrations.AlterField(
model_name='student',
- name='s_major',
+ name='major',
field=models.CharField(blank=True, max_length=50, verbose_name='专业名称'),
),
migrations.AlterField(
model_name='student',
- name='s_name',
+ name='name',
field=models.CharField(blank=True, max_length=100, verbose_name='姓名'),
),
migrations.AlterField(
model_name='student',
- name='s_password',
+ name='password',
field=models.CharField(blank=True, max_length=100, verbose_name='密码'),
),
migrations.AlterField(
model_name='student',
- name='s_sex',
+ name='sex',
field=models.CharField(blank=True, max_length=4, verbose_name='性别'),
),
migrations.AlterField(
model_name='student',
- name='s_username',
+ name='username',
field=models.CharField(blank=True, max_length=30, verbose_name='用户名称'),
),
migrations.AlterField(
diff --git a/EduSystemServer/Student/models.py b/EduSystemServer/Student/models.py
index e0c0548..770cc48 100644
--- a/EduSystemServer/Student/models.py
+++ b/EduSystemServer/Student/models.py
@@ -4,38 +4,6 @@ from django.db import models
# Create your models here.
class Student(models.Model):
sid = models.AutoField(primary_key=True, verbose_name="学生编号", name="sid")
-<<<<<<< Updated upstream
-=======
-<<<<<<< Updated upstream
->>>>>>> Stashed changes
-<<<<<<< HEAD
- 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)
- 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, "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}
-=======
- username = models.CharField(max_length=30, verbose_name="用户名称", name="username", blank=True)
- password = models.CharField(max_length=100, verbose_name="密码", name="password", blank=True)
- name = models.CharField(max_length=100, verbose_name="姓名", name="name", blank=True)
- sex = models.CharField(max_length=4, verbose_name="性别", name="sex", blank=True)
- grade = models.CharField(max_length=20, verbose_name="年级", name="grade", blank=True)
- class_name = models.CharField(max_length=50, verbose_name="班级", name="class_name", blank=True)
- major = models.CharField(max_length=50, verbose_name="专业名称", name="major", blank=True)
-
- def to_dict(self):
- return {"sid": self.sid, "name": self.name, "username": self.username, "password": self.password,
- "sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major}
->>>>>>> 7b09141c358f80dd8877b8665d0d55b629db72aa
-<<<<<<< Updated upstream
-=======
-=======
username = models.CharField(max_length=30, verbose_name="用户名称", name="username", blank=True)
password = models.CharField(max_length=100, verbose_name="密码", name="password", blank=True)
name = models.CharField(max_length=100, verbose_name="姓名", name="name", blank=True)
@@ -47,9 +15,6 @@ class Student(models.Model):
def to_dict(self):
return {"sid": self.sid, "name": self.name, "username": self.username, "password": self.password,
"sex": self.sex, "grade": self.grade, "class_name": self.class_name, "major": self.major}
->>>>>>> Stashed changes
->>>>>>> Stashed changes
-
class Meta:
db_table = "student"
verbose_name = "学生"
diff --git a/EduSystemServer/Student/views.py b/EduSystemServer/Student/views.py
index 1c05c42..1e8e18e 100644
--- a/EduSystemServer/Student/views.py
+++ b/EduSystemServer/Student/views.py
@@ -1,22 +1,13 @@
from django.shortcuts import render
-
# Create your views here.
from django.http import JsonResponse
-<<<<<<< Updated upstream
-from .models import Student
-=======
-<<<<<<< HEAD
-
from EduSystemServer.utils import ResponseUtil
-from Student.models import Student
-=======
from .models import Student
->>>>>>> 1e084d20f30e0b66d5e309a483f87ce5cfe06c39
->>>>>>> Stashed changes
from django.views.decorators.csrf import csrf_exempt
from django.http import QueryDict
from io import BytesIO
from django.http.multipartparser import MultiPartParser
+import json
@csrf_exempt
@@ -34,47 +25,48 @@ def studnets(request):
student.class_name = request_data.get("class_name")
student.major = request_data.get("major")
student.save()
- response = ResponseUtil.ok(student.to_dict(), "更新成功!")
+ response = ResponseUtil.ok(student.to_dict(), "添加成功!")
return JsonResponse(response)
except Exception as E:
return JsonResponse(ResponseUtil.error(E))
elif request.method == "GET":
sid = request.GET.get('sid')
- s_name = request.GET.get('s_name')
- s_sex = request.GET.get('s_sex')
- s_grade = request.GET.get('s_grade')
- s_class_name = request.GET.get('s_class_name')
- s_major = request.GET.get('s_major')
+ name = request.GET.get('name')
+ sex = request.GET.get('sex')
+ grade = request.GET.get('grade')
+ class_name = request.GET.get('class_name')
+ major = request.GET.get('major')
data = []
if sid:
filtered = Student.objects.filter(sid=sid)
for student in filtered:
data.append(student.to_dict())
- elif s_name:
- filtered = Student.objects.filter(s_name=s_name)
+ elif name:
+ filtered = Student.objects.filter(name=name)
for student in filtered:
data.append(student.to_dict())
- elif s_sex:
- filtered = Student.objects.filter(s_sex=s_sex)
+ elif sex:
+ filtered = Student.objects.filter(sex=sex)
for student in filtered:
data.append(student.to_dict())
- elif s_grade:
- filtered = Student.objects.filter(s_grade=s_grade)
+ elif grade:
+ filtered = Student.objects.filter(grade=grade)
for student in filtered:
data.append(student.to_dict())
- elif s_class_name:
- filtered = Student.objects.filter(s_class_name=s_class_name)
+ elif class_name:
+ filtered = Student.objects.filter(class_name=class_name)
for student in filtered:
data.append(student.to_dict())
- elif s_major:
- filtered = Student.objects.filter(s_major=s_major)
+ elif major:
+ filtered = Student.objects.filter(major=major)
for student in filtered:
data.append(student.to_dict())
else:
all_objects = Student.objects.all()
for studnet in all_objects:
data.append(studnet.to_dict())
- return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
+ response = ResponseUtil.ok(data, "查询成功!")
+ return JsonResponse(response)
elif request.method == "DELETE":
parser = MultiPartParser(request.META, BytesIO(request.body), request.upload_handlers, request.encoding)
post_dict = parser.parse()
@@ -82,42 +74,31 @@ def studnets(request):
try:
info = Student.objects.filter(sid=sid).get().to_dict()
Student.objects.filter(sid=sid).delete()
- response = {"code": 200, "message": "删除成功!", "data": info}
+ response = ResponseUtil.ok(info, "删除成功!")
return JsonResponse(response)
except:
- response = {"code": 200, "message": "删除失败,未找到学生信息!"}
- return JsonResponse(response)
+ return JsonResponse(ResponseUtil.error("删除失败,未找到学生信息!"))
elif request.method == "PUT":
put = MultiPartParser(request.META, request, request.upload_handlers, request.encoding).parse()
sid = put[0]['sid']
- s_username = put[0]['s_username']
- s_name = put[0]['s_name']
- s_sex = put[0]['s_sex']
- s_grade = put[0]['s_grade']
- s_class_name = put[0]['s_class_name']
- s_major = put[0]['s_major']
+ username = put[0]['username']
+ name = put[0]['name']
+ sex = put[0]['sex']
+ grade = put[0]['grade']
+ class_name = put[0]['class_name']
+ major = put[0]['major']
try:
- Student.objects.filter(sid=sid).update(s_username=s_username, s_name=s_name, s_sex=s_sex, s_grade=s_grade,
- s_class_name=s_class_name,
- s_major=s_major)
+ Student.objects.filter(sid=sid).update(username=username, name=name, sex=sex, grade=grade,
+ class_name=class_name,
+ major=major)
except:
- Student.objects.create(sid=sid, s_username=s_username, s_name=s_name, s_sex=s_sex, s_grade=s_grade,
- s_class_name=s_class_name,
- s_major=s_major)
+ Student.objects.create(sid=sid, username=username, name=name, sex=sex, grade=grade,
+ class_name=class_name,
+ major=major)
data = Student.objects.filter(sid=sid)[0].to_dict()
- return JsonResponse({'code': 200, 'msg': 'success', 'data': data}, safe=False)
- student_list = Student.objects.all()
- response_json = {"code": 200, "message": "success", "data": []}
- 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)
+ return JsonResponse(ResponseUtil.ok(data, "修改成功!"))
+
def get_select_course_by_id(request):
+
pass
diff --git a/EduSystemServer/course/migrations/0002_auto_20230907_0859.py b/EduSystemServer/course/migrations/0002_auto_20230907_0859.py
index 32adfc7..6085dd4 100644
--- a/EduSystemServer/course/migrations/0002_auto_20230907_0859.py
+++ b/EduSystemServer/course/migrations/0002_auto_20230907_0859.py
@@ -12,12 +12,12 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='course',
- name='c_name',
+ name='name',
field=models.CharField(blank=True, max_length=255, verbose_name='课程名称'),
),
migrations.AlterField(
model_name='course',
- name='c_type',
+ name='type',
field=models.CharField(blank=True, max_length=128, verbose_name='课程类型'),
),
]
diff --git a/EduSystemServer/course/models.py b/EduSystemServer/course/models.py
index fc7381f..e308645 100644
--- a/EduSystemServer/course/models.py
+++ b/EduSystemServer/course/models.py
@@ -13,7 +13,7 @@ class Course(models.Model):
tid = models.ForeignKey(Teacher, to_field="tid", on_delete=models.CASCADE, name="tid")
def to_dict(self):
- return {"cid": self.cid, "c_name": self.name, "type": self.type, "credit": self.credit,
+ return {"cid": self.cid, "name": self.name, "type": self.type, "credit": self.credit,
"tid": self.tid}
class Meta:
diff --git a/EduSystemServer/teacher/migrations/0002_auto_20230907_0859.py b/EduSystemServer/teacher/migrations/0002_auto_20230907_0859.py
index 496b1c5..856bbc4 100644
--- a/EduSystemServer/teacher/migrations/0002_auto_20230907_0859.py
+++ b/EduSystemServer/teacher/migrations/0002_auto_20230907_0859.py
@@ -12,27 +12,27 @@ class Migration(migrations.Migration):
operations = [
migrations.AlterField(
model_name='teacher',
- name='t_dept',
+ name='dept',
field=models.CharField(blank=True, max_length=128, verbose_name='教师所属院系'),
),
migrations.AlterField(
model_name='teacher',
- name='t_education',
+ name='education',
field=models.CharField(blank=True, max_length=128, verbose_name='教师学历'),
),
migrations.AlterField(
model_name='teacher',
- name='t_name',
+ name='name',
field=models.CharField(blank=True, max_length=255, verbose_name='教师名称'),
),
migrations.AlterField(
model_name='teacher',
- name='t_sex',
+ name='sex',
field=models.CharField(blank=True, max_length=128, verbose_name='教师性别'),
),
migrations.AlterField(
model_name='teacher',
- name='t_title',
+ name='title',
field=models.CharField(blank=True, max_length=128, verbose_name='教师职称'),
),
]