• Django-图书管理系统(含源码)


    前段时间翻文件发现了以前学习python和django时做的一个系统,当时的想法是将这玩意做出来应付web开发大作业、课程设计作业甚至是毕设用的,实际上也确实应付了课程设计,功能虽然不算多,但是应付课程设计或者大作业绰绰有余了。

    项目使用python开发,采用Django框架,数据库采用MySQL,根据用户人员的不同分成两套系统,分别是学生系统和管理员系统,功能模块具体分成四个,分别是用户管理模块、图书管理模块、数据管理模块、前端模块。

    1、用户管理模块

    用户管理模块实现的功能包括用户注册(分为学生注册和管理员注册)、用户信息修改、用户登录和判定

    用户注册和登录

     views.py中用户注册及登陆判定代码段

    1. def login(request):#登录
    2. return render(request, 'login.html')
    3. def student_register(request): # 学生注册
    4. name = request.POST.get("student_name") # 获取学生输入的姓名
    5. id = request.POST.get("student_id") # 获取学生输入的学号
    6. major = request.POST.get("student_major") # 获取学生输入的学院
    7. email = request.POST.get("student_email") # 获取学生输入的邮箱
    8. telephone = request.POST.get("student_telephone")
    9. password = request.POST.get("student_password")
    10. result1 = User.objects.filter(account=telephone) # 在用户表中搜索该用户名的记录
    11. result2 = Student.objects.filter(student_id=id) # 在学生表中搜索该学号的记录
    12. context = {}
    13. if len(result1) == 1: # 判断该账户是否存在(即判断是否注册过),如果后台存在记录,则返回相应的提示语句
    14. context["info"] = "该账户已注册!!!"
    15. context["status"] = 0 #零表示注册失败
    16. return render(request, 'login.html', context=context)
    17. else: #该账户是新用户
    18. if len(result2) == 1:#判断该学号是否有学生已使用
    19. context["info"] = "该学号已占用!!!"
    20. context["status"] = 4
    21. return render(request, 'login.html', context=context)
    22. else:
    23. User.objects.create(account=telephone, user_password=password,user_identity='学生')#用create为user表添加一条记录
    24. Student.objects.create(student_name=name,student_id=id,student_major=major,student_tel=telephone,student_email=email)#用create为student表添加一条记录
    25. context["info"] = "注册成功!"
    26. context["status"] = 1 #1表示注册成功
    27. return render(request, 'login.html', context=context)
    28. def manager_register(request): # 管理员注册
    29. name = request.POST.get("manager_name") # 获取管理员输入的姓名
    30. id = request.POST.get("manager_id") # 获取管理员输入的工号
    31. stack = request.POST.get("manager_stack") # 获取管理员输入的书库
    32. email = request.POST.get("manager_email") # 获取管理员输入的邮箱
    33. telephone = request.POST.get("manager_telephone")
    34. password = request.POST.get("manager_password")
    35. result1 = User.objects.filter(account=telephone) # 在用户表中搜索该用户名的记录
    36. result2 = Manager.objects.filter(manager_id=id) # 在管理员表中搜索该工号的使用记录
    37. context = {}
    38. if len(result1) == 1: # 判断该账户是否存在(即判断是否注册过),如果后台存在记录,则返回相应的提示语句
    39. context["info"] = "该账户已注册!!!"
    40. context["status"] = 0 #零表示注册失败
    41. return render(request, 'login.html', context=context)
    42. else: #该账户是新用户
    43. if len(result2) == 1:#判断该工号号是否有管理员已使用
    44. context["info"] = "该工号已占用!!!"
    45. context["status"] = 5
    46. return render(request, 'login.html', context=context)
    47. else:
    48. User.objects.create(account=telephone, user_password=password,user_identity='管理员')#用create为user表添加一条记录
    49. Manager.objects.create(manager_name=name, manager_id=id, manager_stack=stack, manager_tel=telephone,manager_email=email)#用create为manager表添加一条记录
    50. context["info"] = "注册成功!"
    51. context["status"] = 1 #1表示注册成功
    52. return render(request, 'login.html', context=context)
    53. def login_judge(request):#登入判定
    54. global account ,global_sname,global_mname #定义全局变量account,存储该用户的账户,global_sname保存一下该学生的姓名,global_mname保存一下该学生的姓名
    55. account = request.POST.get("telephone")#获取前端输入的账户(手机号)
    56. user_password = request.POST.get("password")
    57. result1 = User.objects.filter(account=account)#在user表里检索是否存在该账户
    58. if len(result1) == 1: # 判断后台是否存在该用户,有则进一步判断密码是否正确
    59. password = result1[0].user_password # 获取后台的密码
    60. identity = result1[0].user_identity # 获取该账户的身份信息
    61. if user_password == password: # 将用户输入的密码和后台密码进行比对,如何正确,判断该账户身份
    62. if identity == '学生':
    63. result2 = Student.objects.filter(student_tel=account)
    64. global_sname = result2[0].student_name # 用全局变量保存一下该学生的姓名
    65. context={
    66. "name":result2[0].student_name,
    67. "id":result2[0].student_id,
    68. "major":result2[0].student_major,
    69. "telephone":result2[0].student_tel,
    70. "email":result2[0].student_email,
    71. }
    72. return render(request, 'student/student_information.html',context) # 跳转到学生主页界面
    73. else:
    74. result = Manager.objects.filter(manager_tel=account) # account为全局变量
    75. global_mname = result[0].manager_name # 用全局变量保存一下该管理员的姓名
    76. context = {
    77. "name": result[0].manager_name,
    78. "id": result[0].manager_id,
    79. "stack": result[0].manager_stack,
    80. "telephone": result[0].manager_tel,
    81. "email": result[0].manager_email,
    82. }
    83. return render(request, 'manager/manager_information.html',context) # 跳转到管理员主页界面
    84. else: # 如果不一致则返回相应提示语句
    85. context = {
    86. "info": "密码错误!!!",
    87. "status": 2
    88. }
    89. return render(request, 'login.html', context=context) # 密码错误回到登入界面
    90. else: # 如果不存在该用户则返回相应的提示语句
    91. context = {
    92. "info": "该账户不存在!!!",
    93. "status": 3
    94. }
    95. return render(request, 'login.html', context=context) # 账户不存在则继续回到登入界面

    用户信息管理

     views.py中用户信息管理代码段

    1. def student_information(request):#个人信息
    2. if request.method == "GET": #此部分是当每次点击侧边导航栏的“个人信息”选项时,都重新显示该用户的个人资料
    3. result = Student.objects.filter(student_tel=account) #account为全局变量
    4. context = {
    5. "name": result[0].student_name,
    6. "id": result[0].student_id,
    7. "major": result[0].student_major,
    8. "telephone": result[0].student_tel,
    9. "email": result[0].student_email,
    10. }
    11. return render(request, 'student/student_information.html', context)#将该用户的个人信息再次传到前端页面
    12. else: #在student_information.html页面的第44行中通过post方式的“保存”按钮跳转到此处,即完成更新数据操作(保存)
    13. email = request.POST.get("email") # 获取邮箱
    14. Student.objects.filter(student_tel=account).update(student_email=email)#更新数据
    15. result = Student.objects.filter(student_tel=account) # account为全局变量 此处再次传值到前端
    16. context = {
    17. "name": result[0].student_name,
    18. "id": result[0].student_id,
    19. "major": result[0].student_major,
    20. "telephone": result[0].student_tel,
    21. "email": result[0].student_email,
    22. }
    23. return render(request, 'student/student_information.html', context) # 将该用户的个人信息再次传到前端页面
    24. def manager_information(request):#个人信息
    25. if request.method == "GET": #此部分是当每次点击侧边导航栏的“个人信息”选项时,都重新显示该管理员的个人资料
    26. result = Manager.objects.filter(manager_tel=account) #account为全局变量
    27. context = {
    28. "name": result[0].manager_name,
    29. "id": result[0].manager_id,
    30. "stack": result[0].manager_stack,
    31. "telephone": result[0].manager_tel,
    32. "email": result[0].manager_email,
    33. }
    34. return render(request, 'manager/manager_information.html', context)#将该用户的个人信息再次传到前端页面
    35. else: #在manager_information.html页面的第44行中通过post方式的“保存”按钮跳转到此处,即完成更新数据操作(保存)
    36. stack = request.POST.get("stack") # 获取书库信息
    37. email = request.POST.get("email") # 获取邮箱
    38. Manager.objects.filter(manager_tel=account).update(manager_email=email,manager_stack=stack)#更新数据
    39. result = Manager.objects.filter(manager_tel=account) # account为全局变量 此处再次传值到前端
    40. context = {
    41. "name": result[0].manager_name,
    42. "id": result[0].manager_id,
    43. "stack": result[0].manager_stack,
    44. "telephone": result[0].manager_tel,
    45. "email": result[0].manager_email,
    46. }
    47. return render(request, 'manager/manager_information.html', context) # 将该用户的个人信息再次传到前端页面

    用户密码修改

     views.py中用户密码修改代码段

    1. def change_password(request):#修改密码
    2. result = User.objects.filter(account=account).first()
    3. password = result.user_password
    4. if request.method == "GET": #此部分是当每次点击侧边导航栏的“修改密码”选项时,显示该界面
    5. return render(request,'student/change_password.html',context={"password":password,"name":global_sname})
    6. else:#此部分是在change_password.html页面中点击保存按钮时完成修改密码的操作
    7. oldPassword = request.POST.get("oldPassword")
    8. newPassword = request.POST.get("newPassword")
    9. reNewPassword = request.POST.get("reNewPassword")#以下是先判断输入的旧密码是否正确,并且两次输入的密码是否一致且都不为空
    10. if password == oldPassword and newPassword == reNewPassword and newPassword and reNewPassword:
    11. User.objects.filter(account=account).update(user_password = newPassword)#更新该用户的密码
    12. password = newPassword
    13. return render(request, 'student/change_password.html', context={"password": password, "name": global_sname})
    14. def change_manager_password(request):#修改管理员的密码
    15. result = User.objects.filter(account=account).first()
    16. password = result.user_password
    17. if request.method == "GET":#此部分是当每次点击侧边导航栏的“修改密码”选项时,显示该界面
    18. return render(request,'manager/change_manager_password.html',context={"password":password,"name":global_mname})
    19. else:#此部分是在change_manager_password.html页面中点击保存按钮时完成修改密码的操作
    20. oldPassword = request.POST.get("oldPassword")
    21. newPassword = request.POST.get("newPassword")
    22. reNewPassword = request.POST.get("reNewPassword")#以下是先判断输入的旧密码是否正确,并且两次输入的密码是否一致且都不为空
    23. if password == oldPassword and newPassword == reNewPassword and newPassword and reNewPassword:
    24. User.objects.filter(account=account).update(user_password = newPassword)#更新该用户的密码
    25. password = newPassword
    26. return render(request, 'manager/change_manager_password.html', context={"password": password, "name": global_mname})

    2、图书管理模块

    图书馆里模块实现的功能与我们日常图书馆的借阅系统相似,学生端包括书籍查询、书籍借阅、书记归还;管理员端包括书籍采购、书籍信息修改等更多扩展功能

    书籍查询及借阅归还,可选择按书籍名或类型查找

     views代码段

    1. def search_book(request):#查找书籍
    2. if request.method == "GET":#此部分是当用户每次点击侧边导航栏的“查找书籍”选项时,都要显示出所有书籍资料
    3. books = Book.objects.all()
    4. types = Type.objects.all()
    5. return render(request, 'student/search_book.html',context={"books": books,"types":types,"name":global_sname }) # 向前端传递所有查找到的书籍信息的集合
    6. else:#student/search_book.html页面的第56行中通过post方式的“搜索”按钮跳转到此处,即完成搜索操作
    7. book_name = request.POST.get("book_name")
    8. type_id = request.POST.get("type_id")
    9. types = Type.objects.all()
    10. if book_name:#如果书名非空,则按书名查找
    11. book_result = Book.objects.filter(book_name=book_name)
    12. if book_result:#如果找到的结果集非空,则输出
    13. return render(request,'student/search_book.html',context={"books":book_result,"types":types,"name":global_sname})
    14. else:#若搜索的结果集为0,那么输出未找到该本书!
    15. book_result = Book.objects.all()
    16. return render(request, 'student/search_book.html',context={"books": book_result, "types": types, "name": global_sname, "status": 0})
    17. else:
    18. if type_id:#如果获取的类型输入框内容不为空,则按类型查找
    19. book_result = Book.objects.filter(book_type=type_id)
    20. if book_result:#如果找到的结果集非空,则输出
    21. return render(request, 'student/search_book.html', context={"books": book_result,"types":types,"name":global_sname})
    22. else:#若搜索的结果集为0,那么输出未找到类型的书!
    23. book_result = Book.objects.all()
    24. return render(request, 'student/search_book.html',context={"books": book_result, "types": types, "name": global_sname,"status":1})
    25. else:#都为空,则显示空列表
    26. return render(request, 'student/search_book.html')
    27. def borrow_book(request):
    28. book_ISBN = request.GET.get("book_ISBN")
    29. result = Book.objects.filter(ISBN=book_ISBN).first()
    30. books = Book.objects.all()
    31. types = Type.objects.all()
    32. if result.book_rest:#如果可借数不为0,则进行book_rest--
    33. rest = result.book_rest-1
    34. Book.objects.filter(ISBN=book_ISBN).update(book_rest=rest)
    35. now_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")#获取当前借书的系统时间
    36. student = Student.objects.filter(student_tel=account).first()
    37. Borrow.objects.create(student_id=student.student_id,student_name=student.student_name,student_tel=account,book_id=book_ISBN,book_name=result.book_name,borrow_time=now_time,rest_time=60)
    38. return render(request, 'student/search_book.html',context={"books": books, "types": types, "name": global_sname}) # 向前端传递所有查找到的书籍信息的集合
    39. else:#可借数为0,则不予借出
    40. return render(request, 'student/search_book.html',context={"books": books, "types": types, "name": global_sname}) # 向前端传递所有查找到的书籍信息的集合
    41. def borrow_record(request):#借书记录
    42. if request.method == "GET":
    43. records = Borrow.objects.filter(student_tel=account)#把当前用户的借阅记录搜索出来
    44. #计算剩余天数
    45. for record in records:
    46. borrow_t = record.borrow_time #获取借阅时间如:2019-11-1 11:40
    47. print(borrow_t)
    48. str1 = borrow_t.split(' ') # 先用空格分割该时间字符串,并保存到列表,str1[0]='2019-11-1' ,str1[1]='11:40'
    49. str2 = str1[0].split('-') #再讲时间按'-'分割开,得到str2,str2[0]='2019',str2[1]='11',str2[2]='1'
    50. borrow_time = datetime.date(int(str2[0]), int(str2[1]), int(str2[2]))#利用date函数得到相对应的借阅时间
    51. now_time = datetime.date(datetime.datetime.now().year, datetime.datetime.now().month,
    52. datetime.datetime.now().day) # 获取当前日期
    53. rest_day = 60 - (now_time - borrow_time).days #最多借阅60天
    54. print(rest_day)
    55. if rest_day>=0:
    56. Borrow.objects.filter(borrow_time = record.borrow_time).update(rest_time = rest_day)
    57. else:
    58. Borrow.objects.filter(borrow_time = record.borrow_time).update(rest_time = 0)
    59. return render(request,'student/borrow_record.html',context={"records":records,"name":global_sname})
    60. def return_book(request):#还书操作,在borrow_record.html页面中点击还书按钮后跳转到此处
    61. borrow_id = request.GET.get("borrow_id")
    62. result1 = Borrow.objects.filter(id = borrow_id).first()
    63. result2 = Book.objects.filter(ISBN = result1.book_id).first()
    64. rest = result2.book_rest+1 #还书后库存+1
    65. Book.objects.filter(ISBN = result2.ISBN).update(book_rest = rest)
    66. Borrow.objects.filter(id=borrow_id).delete() # 当点击还书按钮后,删除该用户的借阅记录
    67. records = Borrow.objects.filter(student_tel=account) # 把当前用户的借阅记录搜索出来
    68. return render(request, 'student/borrow_record.html', context={"records": records, "name": global_sname})

    书籍采购(既书籍入库)以及书籍信息修改等

    views代码段

    1. def manage_book(request):#管理书籍
    2. if request.method == "GET": # 此部分是当用户每次点击侧边导航栏的“管理书籍”选项时,都要显示出所有书籍资料
    3. books = Book.objects.all()
    4. types = Type.objects.all()
    5. return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端传递所有查找到的书籍信息的集合
    6. else: # 在manager/manage_bok.html页面中通过post方式的“搜索”按钮跳转到此处,即完成搜索操作
    7. book_name = request.POST.get("book_name")
    8. type_id = request.POST.get("type_id")
    9. types = Type.objects.all()
    10. if book_name: # 如果书名非空,则按书名查找
    11. book_result = Book.objects.filter(book_name=book_name)
    12. if book_result: # 如果找到的结果集非空,则输出
    13. return render(request, 'manager/manage_book.html',context={"books": book_result, "types": types, "name": global_mname})
    14. else: # 若搜索的结果集为0,那么输出未找到该本书!
    15. book_result = Book.objects.all()
    16. return render(request, 'manager/manage_book.html',
    17. context={"books": book_result, "types": types, "name": global_mname, "status": 0})
    18. else:
    19. if type_id: # 如果获取的类型输入框内容不为空,则按类型查找
    20. book_result = Book.objects.filter(book_type=type_id)
    21. if book_result: # 如果找到的结果集非空,则输出
    22. return render(request, 'manager/manage_book.html',
    23. context={"books": book_result, "types": types, "name": global_mname})
    24. else: # 若搜索的结果集为0,那么输出未找到类型的书!
    25. book_result = Book.objects.all()
    26. return render(request, 'manager/manage_book.html',
    27. context={"books": book_result, "types": types, "name": global_mname, "status": 1})
    28. else: # 都为空,则显示空列表
    29. return render(request, 'manager/manage_book.html')
    30. def add_book(request):#增加书籍的馆藏数量
    31. if request.method == "GET":
    32. ISBN = request.GET.get("book_ISBN1")
    33. result = Book.objects.filter(ISBN=ISBN).first()
    34. number = result.book_number+1 #让该书本的馆藏数量和可借数++
    35. rest = result.book_rest+1
    36. Book.objects.filter(ISBN=ISBN).update(book_number = number,book_rest = rest)
    37. books = Book.objects.all()
    38. types = Type.objects.all()
    39. return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端传递所有查找到的书籍信息的集合
    40. def reduce_book(request):#减少书籍的馆藏数量
    41. if request.method == "GET":
    42. ISBN = request.GET.get("book_ISBN2")
    43. result = Book.objects.filter(ISBN=ISBN).first()
    44. number = result.book_number - 1 #让该书本的馆藏数量和可借数--
    45. rest = result.book_rest -1
    46. Book.objects.filter(ISBN=ISBN).update(book_number = number,book_rest = rest)
    47. books = Book.objects.all()
    48. types = Type.objects.all()
    49. return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端传递所有查找到的书籍信息的集合
    50. def delete_book(request):#清空该书籍
    51. if request.method == "GET":
    52. ISBN = request.GET.get("ISBN")
    53. print(ISBN)
    54. Book.objects.filter(ISBN = ISBN).delete()#在book表里删除该条记录
    55. books = Book.objects.all()
    56. types = Type.objects.all()
    57. return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端传递所有查找到的书籍信息的集合
    58. def alter_book(request):#修改书本详情
    59. types = Type.objects.all()
    60. if request.method == "GET":#此部分是当用户在manage_book.html页面中点击修改书籍是执行,目的是显示当前书本的信息
    61. ISBN = request.GET.get("book_ISBN3")
    62. result = Book.objects.filter(ISBN=ISBN).first()
    63. context={
    64. "ISBN": result.ISBN,
    65. "book_name": result.book_name,
    66. "book_author": result.book_author,
    67. "book_publisher": result.book_publisher,
    68. "book_version": result.book_version,
    69. "book_price": result.book_price,
    70. "book_number": result.book_number,
    71. "book_rest": result.book_rest,
    72. "book_place": result.book_place,
    73. "type_name": result.book_type.type_name,
    74. "name": global_sname,
    75. "types": types
    76. }
    77. return render(request, 'manager/alter_book.html',context) # 向前端传递该书籍的所有信息
    78. else:#此部分是当用户在alter_book.html页面中点击保存按钮后重新更新用户修改后的信息
    79. ISBN = request.POST.get("ISBN")
    80. book_name = request.POST.get("book_name")
    81. book_author = request.POST.get("book_author")
    82. book_publisher = request.POST.get("book_publisher")
    83. book_version = request.POST.get("book_version")
    84. book_price = request.POST.get("book_price")
    85. book_number = request.POST.get("book_number")
    86. book_rest = request.POST.get("book_rest")
    87. book_place = request.POST.get("book_place")
    88. type_name = request.POST.get("type_name")
    89. if book_number.isdigit() and book_rest.isdigit(): # 判断输入的馆藏数和可借数是否为数字
    90. type = Type.objects.filter(type_name=type_name).first() # 书籍类型是外键
    91. Book.objects.filter(ISBN=ISBN).update( book_name=book_name, book_author=book_author, book_publisher=book_publisher,
    92. book_version = book_version,
    93. book_price = book_price, book_number=book_number, book_rest=book_rest,
    94. book_place = book_place, book_type=type) # 在book表里更新刚才修改的书本信息
    95. context = { #把修改后的内容显示出来
    96. "ISBN": ISBN,
    97. "book_name": book_name,
    98. "book_author": book_author,
    99. "book_publisher": book_publisher,
    100. "book_version": book_version,
    101. "book_price": book_price,
    102. "book_number": book_number,
    103. "book_rest": book_rest,
    104. "book_place": book_place,
    105. "type_name": type_name,
    106. "name": global_sname,
    107. "types": types
    108. }
    109. return render(request, 'manager/alter_book.html',context) # 重新向前端传递该书籍的所有信息
    110. else:
    111. result = Book.objects.filter(ISBN=ISBN).first()
    112. context = {
    113. "ISBN": result.ISBN,
    114. "book_name": result.book_name,
    115. "book_author": result.book_author,
    116. "book_publisher": result.book_publisher,
    117. "book_version": result.book_version,
    118. "book_price": result.book_price,
    119. "book_number": result.book_number,
    120. "book_rest": result.book_rest,
    121. "book_place": result.book_place,
    122. "type_name": result.book_type.type_name,
    123. "name": global_sname,
    124. "types": types
    125. }
    126. return render(request, 'manager/alter_book.html', context) # 向前端传递该书籍的所有信息
    127. def add_new_book(request):#添加新书籍
    128. types = Type.objects.all()
    129. if request.method == "GET":#此部分是当每次点击侧边导航栏的“采购书籍”选项时,显示该界面
    130. return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types})
    131. else:#此部分是在add_new_book.html页面中点击确认按钮后完成的添加书籍操作
    132. ISBN = request.POST.get("ISBN")#获取用户在前端输入框中的数据
    133. book_name = request.POST.get("book_name")
    134. book_author = request.POST.get("book_author")
    135. book_publisher = request.POST.get("book_publisher")
    136. book_version = request.POST.get("book_version")
    137. book_price = request.POST.get("book_price")
    138. book_number = request.POST.get("book_number")
    139. book_rest = request.POST.get("book_rest")
    140. book_place = request.POST.get("book_place")
    141. type_name = request.POST.get("type_name")
    142. if book_number.isdigit() and book_rest.isdigit():#判断输入的馆藏数和可借数是否为数字
    143. type = Type.objects.filter(type_name = type_name).first()#书籍类型是外键
    144. Book.objects.create(ISBN=ISBN,book_name=book_name,book_author=book_author,book_publisher=book_publisher,book_version=book_version,
    145. book_price=book_price,book_number=book_number,book_rest=book_rest,book_place=book_place,book_type=type)#在book表里添加新记录
    146. return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types})
    147. else:
    148. return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types})

     3、数据管理模块

    数据管理模块主要是设计数据库的存储和操作,django的ROM机制可以让用户在models上面编写要创建的数据表类型,通过执行迁移,直接在数据库创建数据库表

    models.py代码段

    1. from django.db import models
    2. class User(models.Model): #用户表
    3. account=models.CharField(max_length = 20,primary_key=True)#账号
    4. user_password=models.CharField(max_length = 20)#用户密码
    5. user_identity=models.CharField(max_length = 20)#用户身份
    6. class Student(models.Model): #学生信息表
    7. student_id=models.CharField(max_length = 20,primary_key=True)#学号 主键
    8. student_name=models.CharField(max_length=20)#姓名
    9. student_tel=models.CharField(max_length = 20)#电话
    10. student_major=models.CharField(max_length = 20)#院系
    11. student_email=models.CharField(max_length = 50)#邮箱
    12. class Manager(models.Model): #图书管理员信息表
    13. manager_id=models.CharField(max_length = 20,primary_key=True)#工号 主键
    14. manager_name=models.CharField(max_length=20)#姓名
    15. manager_tel=models.CharField(max_length = 20)#电话
    16. manager_email=models.CharField(max_length = 50)#邮箱
    17. manager_stack=models.CharField(max_length = 20)#管理书库
    18. class Type(models.Model):#书籍类型表
    19. type_id= models.CharField(max_length=20,primary_key=True) # 类型编号,主键
    20. type_name = models.CharField(max_length=20) # 类型名称
    21. class Book(models.Model):#书本信息表
    22. ISBN= models.CharField(max_length = 20,primary_key=True) # 国际标准书号 主键
    23. book_name = models.CharField(max_length=20) # 书名
    24. book_author = models.CharField(max_length=20) # 作者
    25. book_publisher = models.CharField(max_length=20) # 出版社
    26. book_version = models.CharField(max_length=20) # 版本
    27. book_price = models.CharField(max_length=20) # 价格
    28. book_number = models.IntegerField() # 总库存数(馆藏数)
    29. book_rest = models.IntegerField() # 可借数
    30. book_place = models.CharField(max_length=20) # 所属书库
    31. book_type = models.ForeignKey(Type, on_delete=models.CASCADE)#书籍类型
    32. class Borrow(models.Model):#借阅表
    33. student_id= models.CharField(max_length=20) # 借书人学号
    34. student_name = models.CharField(max_length=20) # 借书人姓名
    35. student_tel = models.CharField(max_length=20) # 借书人联系方式
    36. book_id = models.CharField(max_length=20) # 书籍编号
    37. book_name = models.CharField(max_length=20) # 书名
    38. borrow_time = models.CharField(max_length=20) # 借书时间
    39. rest_time = models.IntegerField() # 剩余天数

     settings.py关于数据库的相关设定

    1. DATABASES = {
    2. 'default': {
    3. 'ENGINE': 'django.db.backends.mysql',
    4. 'NAME': 'Library', #数据库名字
    5. 'USER': 'xxxx', #用户名
    6. 'PASSWORD': 'xxxx',#密码
    7. 'HOST': 'localhost', #本地主机
    8. 'PORT': '3306' #端口号
    9. }
    10. }

    4、前端模块

    前端模块是向用户展示的用户界面,通常保存在templates文件夹下,后端通过与前端的数据进行交互,通过路由返回具体的页面实现渲染。

    templates文件夹目录

    urls.py路由路径 

    1. from django.contrib import admin
    2. from django.urls import path,include
    3. from MyApp import views as App_views
    4. urlpatterns = [
    5. path('admin/', admin.site.urls),
    6. path('MyApp/',include('MyApp.urls')),
    7. path('login/',App_views.login),
    8. path('student_register/',App_views.student_register),
    9. path('manager_register/',App_views.manager_register),
    10. path('login_judge/', App_views.login_judge),
    11. path('student_information/',App_views.student_information),
    12. path('search_book/',App_views.search_book),
    13. path('borrow_record/',App_views.borrow_record),
    14. path('change_password/',App_views.change_password),
    15. path('borrow_book/',App_views.borrow_book),
    16. path('return_book/',App_views.return_book),
    17. path('manager_information/', App_views.manager_information),
    18. path('manage_book/', App_views.manage_book),
    19. path('delete_book/', App_views.delete_book),
    20. path('add_book/', App_views.add_book),
    21. path('reduce_book/', App_views.reduce_book),
    22. path('change_manager_password/', App_views.change_manager_password),
    23. path('add_new_book/', App_views.add_new_book),
    24. path('alter_book/', App_views.alter_book),
    25. path('',App_views.login),
    26. ]

    通过django创建的数据库表

    视频演示链接:

    图书管理系统_哔哩哔哩_bilibili

    源代码获取可私信或+QQ:1834661953 

  • 相关阅读:
    [C#]使用C#部署yolov8的目标检测tensorrt模型
    一个完整的初学者指南Django-part2
    飞驰的高铁-第15届蓝桥杯第一次STEMA测评Scratch真题精选
    java计算机毕业设计交通事故档案管理系统源码+数据库+系统+lw文档+mybatis+运行部署
    【论文笔记】Diffusion-based 3D Object Detection with Random Boxes
    Matlab:Matlab编程语言学习之变量&常量/数据类型的简介、技巧总结案例应用之详细攻略
    【办公类-22-14】周计划系列(5-5)“周计划-05 周计划表格内教案部分“节日”清空改成“节日“” (2024年调整版本)Win32
    【Unity3D日常开发】Unity3D中打包WEBGL后读取本地文件数据
    洛谷 P1640 [SCOI2010] 连续攻击游戏(二分图最大匹配)
    Java异常处理
  • 原文地址:https://blog.csdn.net/Gefangen/article/details/125544793