From 80e9d7d982c833bafcd3ac74210403af47d9b6d8 Mon Sep 17 00:00:00 2001 From: crwed <105581012+crwed@users.noreply.github.com> Date: Sun, 2 Jun 2024 02:17:15 +0800 Subject: [PATCH] * --- app01/apps.py | 1 - app01/models.py | 5 ----- app01/views.py | 16 ---------------- djangoProject/urls.py | 21 +++++++-------------- djangoProject/wsgi.py | 3 --- 5 files changed, 7 insertions(+), 39 deletions(-) diff --git a/app01/apps.py b/app01/apps.py index 60a3620..5fa7536 100644 --- a/app01/apps.py +++ b/app01/apps.py @@ -1,6 +1,5 @@ from django.apps import AppConfig - class App01Config(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'app01' diff --git a/app01/models.py b/app01/models.py index f0c3546..4b3d158 100644 --- a/app01/models.py +++ b/app01/models.py @@ -1,7 +1,5 @@ from django.db import models - -# Create your models here. class StuInfo(models.Model): username = models.CharField(verbose_name='用户名', max_length=32, unique=True) password = models.CharField(verbose_name='密码', max_length=64) @@ -14,21 +12,18 @@ class StuInfo(models.Model): department = models.ForeignKey(verbose_name='学院', to='Department', to_field='id', on_delete=models.CASCADE) course = models.ManyToManyField(to='CourseInfo', through='Select') - class Department(models.Model): department_name = models.CharField(verbose_name='学院名', max_length=32) def __str__(self): return self.department_name - class CourseInfo(models.Model): course_name = models.CharField(verbose_name='课程名称', max_length=32) course_brief = models.CharField(verbose_name='课程介绍', max_length=128, default='无') class_hour = models.SmallIntegerField(verbose_name='课时') points = models.SmallIntegerField(verbose_name='学分') - class AdminInfo(models.Model): username = models.CharField(verbose_name='用户名', max_length=32) password = models.CharField(verbose_name='密码', max_length=64) diff --git a/app01/views.py b/app01/views.py index 549583d..c1e4f85 100644 --- a/app01/views.py +++ b/app01/views.py @@ -4,12 +4,10 @@ from django.contrib import messages from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger # 分页组件 from app01 import models - # Create your views here. def index(request): return render(request, 'homepage.html') - def login(request): if request.method == 'GET': return render(request, 'login.html', ) @@ -37,11 +35,9 @@ def login(request): else: return HttpResponse('failed') - def manage_homepage(request): return render(request, 'homepage_admin.html') - def manage_student(request): search_key = request.GET.get('key', '') students = models.StuInfo.objects.filter(name__contains=search_key).all() @@ -56,7 +52,6 @@ def manage_student(request): students = paginator.page(paginator.num_pages) return render(request, 'student_manage.html', locals()) - def manage_course(request): search_key = request.GET.get('key', '') courses = models.CourseInfo.objects.filter(course_name__contains=search_key).all() @@ -71,7 +66,6 @@ def manage_course(request): courses = paginator.page(paginator.num_pages) return render(request, 'course_manage.html',locals()) - class StuForm(ModelForm): class Meta: model = models.StuInfo @@ -83,7 +77,6 @@ class StuForm(ModelForm): for field in self.fields.values(): field.widget.attrs['class'] = 'form-control' - def add_student(request): if request.method == 'GET': form = StuForm() @@ -97,7 +90,6 @@ def add_student(request): else: return render(request, 'student_add.html', {'form': form}) - def edit_student(request, sid): queryset = models.StuInfo.objects.filter(id=sid).first() if request.method == 'GET': @@ -143,7 +135,6 @@ def add_course(request): else: return render(request, 'course_add.html', {'form': form}) - def edit_course(request, cid): queryset = models.CourseInfo.objects.filter(id=cid).first() if request.method == 'GET': @@ -158,17 +149,11 @@ def edit_course(request, cid): else: return render(request, 'course_edit.html', {'form': form}) - def delete_course(request, cid): models.CourseInfo.objects.filter(id=cid).first().delete() return redirect('/manage/course/list/') - def manage_select(request): - # student_objs = models.StuInfo.objects.all() - # queryset = {} - # for obj in student_objs: - # queryset[obj.name] = obj.course.all() # 获取当前页数 selects = models.Select.objects.all() print(selects) @@ -182,7 +167,6 @@ def manage_select(request): selects = paginator.page(paginator.num_pages) return render(request, 'select_manage.html', locals()) - def delete_select(request, id): models.Select.objects.filter(id=id).first().delete() return redirect('/manage/select/list/') diff --git a/djangoProject/urls.py b/djangoProject/urls.py index bf6314a..f5950bd 100644 --- a/djangoProject/urls.py +++ b/djangoProject/urls.py @@ -20,41 +20,34 @@ from app01 import views urlpatterns = [ path('admin/', admin.site.urls), - # 主页,登录两个页面的URL - # 主页 path('', views.index), # 登录 path('login/', views.login), - - - # 学生选课页面,学生已选页面的URL # 学生选课页面 path('stu/index//', views.student_index, name='student_index'), # 已选页面 path('stu/selected//', views.student_selected, name='student_selected'), - # 管理员主页,学生信息查增改删,课程信息查增 - # 管理员首页 path('manage/homepage/', views.manage_homepage), - # 学生信息列表页面 + # 学生信息列表 path('manage/stu/list/', views.manage_student), - # 学生信息添加页面 + # 学生信息添加 path('manage/stu/add/', views.add_student), - # 学生信息编辑页面 + # 学生信息编辑 path('manage/stu/edit//', views.edit_student), # 学生信息删除url path('manage/stu/del//', views.delete_student), - # 课程列表页面 + # 课程列表 path('manage/course/list/', views.manage_course), - # 课程添加页面 + # 课程添加 path('manage/course/add/', views.add_course), - # 课程信息编辑页面 + # 课程信息编辑 path('manage/course/edit//', views.edit_course), # 课程信息删除url path('manage/course/del//', views.delete_course), - # 选课列表页面 + # 选课列表 path('manage/select/list/', views.manage_select), # 删除选课信息url path('manage/select/del//', views.delete_select), diff --git a/djangoProject/wsgi.py b/djangoProject/wsgi.py index cf736fe..93e4e17 100644 --- a/djangoProject/wsgi.py +++ b/djangoProject/wsgi.py @@ -1,8 +1,6 @@ """ WSGI config for djangoProject project. - It exposes the WSGI callable as a module-level variable named ``application``. - For more information on this file, see https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ """ @@ -12,5 +10,4 @@ import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djangoProject.settings') - application = get_wsgi_application()