1. 一对一 班级  模态增加 编辑

  1. def classes(request):
  2. data = sqlheper.get_list("select cid,title from class",[])
  3. return render(request, "classes.html", {"data": data})
  4.  
  5. def motai_add_class(request):
  6. ret = {'status': True, 'message': None}
  7. title = request.POST.get('title')
  8. try:
  9. nid = request.POST.get('nid')
  10. content = request.POST.get('content')
  11. sqlheper.motify_sql('insert into class(title) values(%s)',[title,])
  12. except Exception as e:
  13. ret['status'] = False
  14. ret['message'] = "处理异常"
  15.  
  16. return HttpResponse(json.dumps(ret))
  17.  
  18. def modal_edit_class(request):
  19. print(request.POST)
  20. ret = {'status': True, 'message':None}
  21. try:
  22. id = request.POST.get('id')
  23. title = request.POST.get('title')
  24. sqlheper.motify_sql('update class set title=%s where cid=%s',[title,id,])
  25. except Exception as e:
  26. ret['status'] = False
  27. ret['message'] = "处理异常"
  28.  
  29. return HttpResponse(json.dumps(ret))

classes.html

2.一对多 学生班级  模态增加 编辑

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <style>
  7. .hide{
  8. display: none;
  9. }
  10. .shadow{
  11. position: fixed;
  12. top: 0;
  13. bottom: 0;
  14. left: 0;
  15. right: 0;
  16. background-color: black;
  17. z-index: 999;
  18. opacity: 0.4;
  19. }
  20. .Modal{
  21. position: fixed;
  22. top: 50%;
  23. left: 50%;
  24. width: 400px;
  25. height: 300px;
  26. margin-left: -200px;
  27. margin-top: -150px;
  28. z-index: 1000;
  29. background-color: white;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34.  
  35. <h1>班级学员</h1>
  36.  
  37. <div>
  38. <a id="addStudent">模态框增加</a>
  39. </div>
  40.  
  41. <table border="1px">
  42. <thead>
  43. <tr>
  44. <td>学员名称</td>
  45. <td>学生名称</td>
  46. <td>班级名称</td>
  47. <td>模态操作</td>
  48. </tr>
  49. </thead>
  50. <tbody>
  51. {% for row in student_list %}
  52. <tr>
  53. <td>{{ row.sid }}</td>
  54. <td>{{ row.name }}</td>
  55. <td clsId="{{ row.class_id }}">{{ row.title }}</td>
  56. <td>
  57. <a class="btn-edit">编辑</a>
  58. <a >删除</a>
  59. </td>
  60. </tr>
  61. {% endfor %}
  62. </tbody>
  63. </table>
  64.  
  65. <div id="shadow" class="shadow hide"></div>
  66.  
  67. {#增加#}
  68. <div id="addModal" class="Modal hide">
  69.  
  70. <p>学生名称:
  71. <input id="add_name" type="text" name="add_name">
  72. </p>
  73. <p>学生性别:
  74. <input id="add_sex" type="text" name="add_sex">
  75. </p>
  76. <p>班级名称:
  77. <select id="add_classId" name="add_classId">
  78. {% for row in class_list %}
  79. <option value="{{ row.cid }}">{{ row.title }}</option>
  80. {% endfor %}
  81. </select>
  82. </p>
  83.  
  84. <input id="btnAdd" type="button" value="提交"><span id="addError"></span>
  85. <input id="btnCancle" type="button" value="取消">
  86.  
  87. </div>
  88.  
  89. {#编辑#}
  90. <div id="editModal" class="Modal hide">
  91. <h3>编辑学生信息</h3>
  92. <p>
  93. 姓名:<input id="editName" type="text" name="name" placeholder="姓名" />
  94. <input type="text" id="editId" style="display: none" />
  95. </p>
  96. <p>
  97. 班级:
  98. <select id="editClassId" name="classId">
  99. {% for row in class_list %}
  100. <option value="{{ row.cid }}">{{ row.title }}</option>
  101. {% endfor %}
  102. </select>
  103. </p>
  104. <input id="btnEdit" type="button" value="更新" />
  105. <span id="editError" style="color: red;"></span>
  106. <input id="btnCancle" type="button" value="取消" />
  107. </div>
  108.  
  109. <script src="/static/jquery-3.2.1.js"></script>
  110.  
  111. <script>
  112.  
  113. $(function () {
  114.  
  115. {# 增加#}
  116.  
  117. $("#addStudent").click(function () {
  118. $("#shadow,#addModal").removeClass("hide");
  119. });
  120.  
  121. $("#btnCancle").click(function () {
  122. $("#shadow,#addModal").addClass("hide");
  123. $("#editModal").addClass("hide");
  124. });
  125.  
  126. $("#btnAdd").click(function () {
  127. var add_name=$("#add_name").val();
  128. var add_age=$("#add_sex").val();
  129. var add_classId=$("#add_classId").val();
  130. $.ajax({
  131. url:"/motai_add_student/",
  132. type:"POST",
  133. data:{"add_name":add_name,"add_age":add_age,"add_classId":add_classId},
  134. success:function (arg) {
  135. arg = JSON.parse(arg);
  136. if (arg.status){
  137. location.reload();
  138. }else {
  139. $("#addError").text(arg.message);
  140. }
  141. }
  142. })
  143.  
  144. });
  145.  
  146. {# 编辑 #}
  147. $('.btn-edit').click(function(){
  148. $('#shadow,#editModal').removeClass('hide');
  149.  
  150. var tds = $(this).parent().prevAll();
  151. var studentId = $(tds[2]).text();
  152. var studentName = $(tds[1]).text();
  153. var classId = $(tds[0]).attr('clsid');
  154.  
  155. console.log(studentId,studentName,classId);
  156.  
  157. $('#editId').val(studentId);
  158. $('#editName').val(studentName);
  159. $('#editClassId').val(classId);
  160. });
  161.  
  162. $('#btnEdit').click(function(){
  163. $.ajax({
  164. url:'/motai_edit_student/',
  165. type: 'POST',
  166. data: {'sid': $('#editId').val(), 'name':$('#editName').val(),'class_id': $('#editClassId').val()},
  167. dataType: 'JSON', //JSON.parse(arg)
  168. success:function(arg){
  169. if(arg.status){
  170. location.reload();
  171. }else{
  172. $('#editError').text(arg.message);
  173. }
  174. }
  175. })
  176. });
  177. })
  178.  
  179. </script>
  180.  
  181. </body>
  182. </html>

student.html

  1. def student(request):
  2. student_list = sqlheper.get_list("select student.sid,student.name,student.class_id,class.title from student left join class on student.class_id=class.cid",[])
  3.  
  4. class_list = sqlheper.get_list("select cid,title from class",[])
  5.  
  6. return render(request, "student.html", {"student_list":student_list, "class_list":class_list})
  7.  
  8. def motai_add_student(request):
  9. print(request.POST)
  10. ret = {"status":True,"message":None}
  11. try:
  12. name = request.POST.get("add_name")
  13. age = request.POST.get("add_age")
  14. classId = request.POST.get("add_classId")
  15.  
  16. sqlheper.motify_sql("insert into student(name,age,class_id) values(%s,%s,%s)",[name,age,classId,])
  17. except Exception as e:
  18. ret["status"] = False
  19. ret["message"] = str(e)
  20. return HttpResponse(json.dumps(ret))
  21.  
  22. def motai_edit_student(request):
  23. ret = {'status': True,'message': None}
  24. try:
  25.  
  26. print(request.POST)
  27. sid = request.POST.get('sid')
  28. name = request.POST.get('name')
  29. class_id = request.POST.get('class_id')
  30. sqlheper.motify_sql('update student set name=%s,class_id=%s where sid=%s',[name,class_id,sid,])
  31. except Exception as e:
  32. ret['status'] = False
  33. ret['message'] = str(e)
  34. return HttpResponse(json.dumps(ret))

Views

3.多对多 老师 班级  模态增加 编辑

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <style>
  7. .hide{
  8. display: none;
  9. }
  10. .shadow{
  11. position: fixed;
  12. top: 0;
  13. bottom: 0;
  14. left: 0;
  15. right: 0;
  16. background-color: black;
  17. z-index: 999;
  18. opacity: 0.4;
  19. }
  20. .Modal{
  21. position: fixed;
  22. top: 50%;
  23. left: 50%;
  24. width: 400px;
  25. height: 300px;
  26. margin-left: -200px;
  27. margin-top: -150px;
  28. z-index: 1000;
  29. background-color: white;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34.  
  35. <h1>老师 班级管理</h1>
  36.  
  37. <div>
  38.  
  39. <a id="addModal">模态框增加</a>
  40. </div>
  41.  
  42. <table border="solid" >
  43. <thead>
  44. <tr>
  45. <td>ID</td>
  46. <td>老师名称</td>
  47. <td>班级名称</td>
  48. <td>操作</td>
  49. </tr>
  50. </thead>
  51. <tbody>
  52. {% for row in teacher_list %}
  53. <tr>
  54. <td>{{ row.tid }}</td>
  55. <td>{{ row.name }}</td>
  56. <td>
  57. {% for item in row.titles %}
  58. {{ item }}
  59. {% endfor %}
  60. </td>
  61. <td>
  62. <a class="editModal">编辑</a>
  63. <a class="delModal">删除</a>
  64. </td>
  65. </tr>
  66. {% endfor %}
  67. </tbody>
  68.  
  69. </table>
  70.  
  71. <div id="shadow" class="shadow hide"></div>
  72.  
  73. <div id="add_tea_cls" class="Modal hide">
  74.  
  75. <p>老师名称:
  76. <input id="add_name" type="text" name="add_name">
  77. </p>
  78.  
  79. <p>班级名称:
  80. <select id="add_classId" name="add_classId" multiple>
  81. {% for row in class_list %}
  82. <option value="{{ row.cid }}">{{ row.title }}</option>
  83. {% endfor %}
  84. </select>
  85. </p>
  86. <input id="btnAdd" type="button" value="提交"><span id="addError"></span>
  87. <input id="btnCancle" type="button" value="取消">
  88.  
  89. </div>
  90.  
  91. <div id="edit_tea_cls" class="Modal hide">
  92.  
  93. <p>老师名称:
  94. <input id="add_name" type="text" name="add_name">
  95. </p>
  96.  
  97. <p>班级名称:
  98. <select id="add_classId" name="add_classId" multiple>
  99. {% for row in class_list %}
  100. <option value="{{ row.cid }}">{{ row.title }}</option>
  101. {% endfor %}
  102. </select>
  103. </p>
  104. <input id="btnEdit" type="button" value="提交"><span id="addError"></span>
  105. <input id="cacleEdit" type="button" value="取消">
  106.  
  107. </div>
  108.  
  109. <script src="/static/jquery-3.2.1.js"></script>
  110.  
  111. <script>
  112.  
  113. $(function () {
  114.  
  115. {# 增加#}
  116. $("#addModal").click(function () {
  117. $("#shadow,#add_tea_cls").removeClass("hide");
  118. });
  119.  
  120. $("#btnCancle").click(function () {
  121. $("#shadow,#add_tea_cls").addClass("hide");
  122. });
  123.  
  124. $("#btnAdd").click(function () {
  125. tname=$("#add_name").val();
  126. class_list=$("#add_classId").val();
  127. console.log(class_list)
  128. $.ajax({
  129. url:"/new_teacher/",
  130. type:"POST",
  131. data:{"tname":tname,"class_list":class_list},
  132. success:function (arg) {
  133. arg = JSON.parse(arg);
  134. if (arg.status){
  135. location.reload();
  136. }else {
  137. $("#addError").text(arg.message);
  138. }
  139. }
  140. })
  141. });
  142.  
  143. {# 编辑#}
  144. $(".editModal").click(function () {
  145. $("#shadow").removeClass("hide");
  146. $("#edit_tea_cls").removeClass("hide");
  147. });
  148.  
  149. $("#cacleEdit").click(function () {
  150. $("#shadow,#edit_tea_cls").addClass("hide");
  151. });
  152.  
  153. })
  154.  
  155. </script>
  156.  
  157. </body>
  158. </html>

teacher.html

  1. def teacher(request):
  2.  
  3. teacher_list=sqlheper.get_list("""
  4. select teacher.tid as tid,teacher.name,class.title from teacher
  5. left join teacher_class on teacher_class.teacher_id=teacher.tid
  6. left join class on class.cid=teacher_class.class_id""",[])
  7. # print(teacher_list)
  8. result = {}
  9. for row in teacher_list:
  10. tid = row["tid"]
  11. if tid in result:
  12. result[tid]["titles"].append(row["title"])
  13. else:
  14. result[tid] = {"tid":row["tid"],"name":row["name"],"titles":[row["title"],]}
  15.  
  16. class_list = sqlheper.get_list("select cid,title from class",[])
  17.  
  18. return render(request, "teacher.html_模态增加 老师班级", {"teacher_list":result.values(), "class_list":class_list})
  19.  
  20. ###模态增加
  21. def new_teacher(request):
  22. print(request.POST)
  23. ret = {'status': True, 'message': None}
  24. try:
  25. class_list=request.POST.getlist("class_list[]")
  26. tname=request.POST.get("tname")
  27. print(class_list)
  28. print(tname)
  29. teacher_id=sqlheper.get_IncrementId("insert into teacher(name) values(%s)",[tname,])
  30. for item in class_list:
  31. sqlheper.motify_sql("insert into teacher_class(teacher_id,class_id) values(%s,%s)",[teacher_id,item,])
  32. except Exception as e:
  33. ret['status'] = False
  34. ret['message'] = str(e)
  35. return HttpResponse(json.dumps(ret))

views

4.多对多 老师 班级  新url  增加 编辑

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6.  
  7. </head>
  8. <body>
  9.  
  10. <h1>老师 班级管理</h1>
  11.  
  12. <div>
  13.  
  14. <a href="/add_page_teacher/">增加</a>
  15. </div>
  16.  
  17. <table border="solid" >
  18. <thead>
  19. <tr>
  20. <td>ID</td>
  21. <td>老师名称</td>
  22. <td>班级名称</td>
  23. <td>操作</td>
  24. </tr>
  25. </thead>
  26. <tbody>
  27. {% for row in teacher_list %}
  28. <tr>
  29. <td>{{ row.tid }}</td>
  30. <td>{{ row.name }}</td>
  31. <td>
  32. {% for item in row.titles %}
  33. {{ item }}
  34. {% endfor %}
  35. </td>
  36. <td>
  37. <a href="/edit_page_teacher/?tid={{ row.tid }}">编辑</a>
  38. <a >删除</a>
  39. </td>
  40. </tr>
  41. {% endfor %}
  42. </tbody>
  43.  
  44. </table>
  45.  
  46. </body>
  47. </html>

teacher.html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8.  
  9. <h1>增加老师</h1>
  10.  
  11. <form action="/add_teacher/" method="POST">
  12. <p>老师名称: <input type="text" name="name"></p>
  13. <input type="submit">
  14. </form>
  15.  
  16. </body>
  17. </html>

add_page.teacher

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. </head>
  7. <body>
  8.  
  9. <h3>编辑老师班级</h3>
  10.  
  11. <form action="/edit_page_teacher/?tnid={{ tname.tid }}" method="post">
  12.  
  13. <p>老师名称:<input type="text" name="name" value="{{ tname.name }}"></p>
  14.  
  15. <p>班级名称:
  16. <select name="class_ids" multiple size="">
  17. {% for item in class_list %}
  18. {% if item.cid in class_ids %}
  19. <option selected value="{{ item.cid }}">{{ item.title }}</option>
  20. {% else %}
  21. <option value="{{ item.cid }}">{{ item.title }}</option>
  22. {% endif %}
  23. {% endfor %}
  24. </select>
  25.  
  26. <p><input type="submit" value="提交"></p>
  27. </p>
  28.  
  29. </form>
  30.  
  31. </body>
  32. </html>

edit_teacher

  1. ###网页显示
  2. def teacher(request):
  3.  
  4. teacher_list=sqlheper.get_list("""
  5. select teacher.tid as tid,teacher.name,class.title from teacher
  6. left join teacher_class on teacher_class.teacher_id=teacher.tid
  7. left join class on class.cid=teacher_class.class_id""",[])
  8. # print(teacher_list)
  9. result = {}
  10. for row in teacher_list:
  11. tid = row["tid"]
  12. if tid in result:
  13. result[tid]["titles"].append(row["title"])
  14. else:
  15. result[tid] = {"tid":row["tid"],"name":row["name"],"titles":[row["title"],]}
  16.  
  17. class_list = sqlheper.get_list("select cid,title from class",[])
  18.  
  19. return render(request, "teacher.html", {"teacher_list":result.values(), "class_list":class_list})
  20.  
  21. ###网页增加
  22. def add_page_teacher(request):
  23. if request.method=="GET":
  24. obj = sqlheper.SqlHelper()
  25. class_list = obj.get_list("select cid,title from class",[])
  26. obj.close()
  27. return render(request,"add_page_teacher.html",{"class_list":class_list})
  28. else:
  29.  
  30. name = request.POST.get("name")
  31. obj = sqlheper.SqlHelper()
  32. teacher_id = obj.get_lastrowid("insert into teacher(name) values(%s)",[name,])
  33. obj.close()
  34.  
  35. class_ids = request.POST.getlist("class_ids")
  36. print(class_ids)
  37.  
  38. data_list = []
  39. for cls_id in class_ids:
  40. temp = (teacher_id, cls_id,)
  41. data_list.append(temp)
  42.  
  43. obj = sqlheper.SqlHelper()
  44. obj.multiple_modify('insert into teacher_class(teacher_id,class_id) values(%s,%s)', data_list)
  45. obj.close()
  46. return redirect('/teacher/')
  47.  
  48. ###网页编辑
  49. def edit_page_teacher(request):
  50. if request.method=="GET":
  51. teacher_id = request.GET.get("tid")
  52. obj = sqlheper.SqlHelper()
  53. tname = obj.get_one("select tid,name from teacher where tid=%s",[teacher_id,])
  54.  
  55. class_list = obj.get_list("select cid,title from class",[])
  56.  
  57. class_ids = obj.get_list("select class_id from teacher_class where teacher_id =%s",[teacher_id,])
  58. obj.close()
  59.  
  60. temp = []
  61. for i in class_ids:
  62. temp.append(i['class_id'])
  63.  
  64. return render(request,"edit_page_teacher.html",{
  65. "tname":tname,
  66. "class_list":class_list,
  67. "class_ids":temp,
  68. })
  69. else:
  70. tid=request.GET.get("tnid")
  71. name=request.POST.get("name")
  72. class_ids=request.POST.getlist("class_ids")
  73.  
  74. obj = sqlheper.SqlHelper()
  75. obj.modify("update teacher set name=%s where tid=%s",[name,tid,])
  76. obj.modify('delete from teacher_class where teacher_id=%s',[tid,])
  77. data_list = []
  78. for cls_id in class_ids:
  79. temp = (tid,cls_id)
  80. data_list.append(temp)
  81. obj.multiple_modify('insert into teacher_class(teacher_id,class_id) values(%s,%s)',data_list)
  82. obj.close()
  83. return redirect('/teacher/')

views

5.多对多 老师 班级 模态  增加 编辑

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Title</title>
  6. <style>
  7. .hide{
  8. display: none;
  9. }
  10. .shadow{
  11. position: fixed;
  12. top: 0;
  13. bottom: 0;
  14. left: 0;
  15. right: 0;
  16. background-color: black;
  17. z-index: 999;
  18. opacity: 0.4;
  19. }
  20. .loading{
  21. position: fixed;
  22. width: 32px;
  23. height: 32px;
  24. left: 50%;
  25. top:50%;
  26. margin-left: -16px;
  27. margin-top: -16px;
  28. background-color: rebeccapurple;
  29. background-image: url("/static/images/loading.gif") ;
  30. background-size: 100%;
  31.  
  32. }
  33. .Modal{
  34. position: fixed;
  35. top: 50%;
  36. left: 50%;
  37. width: 400px;
  38. height: 300px;
  39. margin-left: -200px;
  40. margin-top: -150px;
  41. z-index: 1000;
  42. background-color: white;
  43. }
  44. </style>
  45. <link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
  46. <link rel="stylesheet" href="/static/plugins/font-awesome-4.7.0/css/font-awesome.css">
  47. </head>
  48. <body>
  49.  
  50. <h1 >老师 班级管理</h1>
  51.  
  52. <div class="btn btn-success">
  53.  
  54. <a id="addModal">模态框增加</a>
  55. </div>
  56.  
  57. <table border="solid" class="table table-striped">
  58. <thead>
  59. <tr>
  60. <td>ID</td>
  61. <td>老师名称</td>
  62. <td>班级名称</td>
  63. <td>操作</td>
  64. </tr>
  65. </thead>
  66. <tbody>
  67. {% for row in teacher_list %}
  68. <tr>
  69. <td>{{ row.tid }}</td>
  70. <td>{{ row.name }}</td>
  71. <td>
  72. {% for item in row.titles %}
  73. {{ item }}
  74. {% endfor %}
  75. </td>
  76. <td>
  77. <a class="editModal">编辑</a>
  78. <a class="delModal">删除</a>
  79. </td>
  80. </tr>
  81. {% endfor %}
  82. </tbody>
  83.  
  84. </table>
  85.  
  86. <div id="shadow" class="shadow hide"></div>
  87.  
  88. <div id="loading" class="loading hide"></div>
  89.  
  90. <div id="add_tea_cls" class="Modal hide">
  91.  
  92. <p>老师名称:
  93. <input id="add_name" type="text" name="add_name">
  94. </p>
  95.  
  96. <p>班级名称:
  97. <select id="add_classId" name="add_classId" multiple size="">
  98.  
  99. </select>
  100. </p>
  101. <input id="btnAdd" type="button" value="提交"><span id="addError"></span>
  102. <input id="btnCancle" type="button" value="取消">
  103.  
  104. </div>
  105.  
  106. <div id="edit_tea_cls" class="Modal hide">
  107. <input type="text" id="hide_id" style="display: none">
  108.  
  109. <p>老师名称:
  110. <input id="edit_name" type="text" name="add_name">
  111. </p>
  112.  
  113. <p>班级名称:
  114. <select id="edit_classId" name="edit_classId" multiple size="">
  115.  
  116. </select>
  117. </p>
  118. <input id="btnEdit" type="button" value="提交"><span id="addError"></span>
  119. <input id="cacleEdit" type="button" value="取消">
  120.  
  121. </div>
  122.  
  123. <script src="/static/jquery-3.2.1.js"></script>
  124.  
  125. <script>
  126.  
  127. $(function () {
  128.  
  129. {# 增加#}
  130. $("#addModal").click(function () {
  131. $("#shadow,#loading").removeClass("hide");
  132. $.ajax({
  133. url:"/get_all_class/",
  134. type:"GET",
  135. dataType:"JSON",
  136. success:function (arg) {
  137. $.each(arg,function (i,row) {
  138. var tag = $("<option>"); /*var tag = document.createElement('option');*/
  139. tag.text(row.title); /*tag.innerHTML = row.title;*/
  140. tag.prop("value",row.cid);
  141. $("#add_classId").append(tag); /*tag.setAttribute('value',row.id);*/
  142. });
  143. $('#loading').addClass('hide');
  144. $('#add_tea_cls').removeClass('hide');
  145. }
  146. })
  147. });
  148.  
  149. $("#btnCancle").click(function () {
  150. $("#shadow,#add_tea_cls").addClass("hide");
  151. });
  152.  
  153. $("#btnAdd").click(function () {
  154. var tname=$("#add_name").val();
  155. var class_list=$("#add_classId").val();
  156. console.log(class_list);
  157. $.ajax({
  158. url:"/new_teacher/",
  159. type:"POST",
  160. data:{"tname":tname,"class_list":class_list},
  161. dataType:"JSON",
  162. traditional: true, // 如果提交的数据的值有列表,则需要添加此属性
  163. success:function (arg) {
  164.  
  165. if (arg.status){
  166. location.reload();
  167. }else {
  168. alert(arg.message);
  169. }
  170. }
  171. })
  172. });
  173.  
  174. {# 编辑#}
  175. $(".editModal").click(function () {
  176. $("#shadow,#loading").removeClass("hide");
  177. var ids=$(this).parent().prevAll()[2];
  178. var id=$(ids).text();
  179. $("#hide_id").val(id);
  180. $.ajax({
  181. url: "/edit_tea_cls/",
  182. type: "POST",
  183. dataType: "JSON",
  184. data:{"id":id},
  185. success: function (arg) {
  186.  
  187. class_list = arg[0];
  188. teacher_info = arg[1];
  189. class_lds = arg[2];
  190. console.log(class_lds);
  191. $("#edit_classId").empty();
  192. $.each(class_list, function (i, row) {
  193. var tag = $("<option>");
  194. tag.text(row.title);
  195. tag.prop("value", row.cid);
  196.  
  197. if(class_lds.indexOf(row.cid) == -1){
  198. $("#edit_classId").append(tag);
  199. }else {
  200. tag.prop("selected","selected");
  201. $("#edit_classId").append(tag);
  202. }
  203. });
  204. $("#edit_name").val(teacher_info["name"]);
  205.  
  206. $('#loading').addClass('hide');
  207. $('#edit_tea_cls').removeClass('hide');
  208. }
  209. });
  210.  
  211. $("#cacleEdit").click(function () {
  212. $("#shadow,#edit_tea_cls").addClass("hide");
  213. });
  214. })
  215.  
  216. {# 编辑提交#}
  217. $("#btnEdit").click(function () {
  218. var tid= $("#hide_id").val();
  219. var name = $("#edit_name").val();
  220. var class_ids = $("#edit_classId").val();
  221. $.ajax({
  222. url:"/modal_edit_teacher/",
  223. type:"post",
  224. dataType:"JSON",
  225. traditional:true,
  226. data:{"tid":tid,"name":name,"del_class_id":del_class_id},
  227. $.ajax({
  228. url:"/modal_edit_teacher/",
  229. type:"post",
  230. dataType:"JSON",
  231. traditional:true,
  232. data:{"tid":tid,"name":name,"class_ids":class_ids},
  233. success:function (arg) {
  234. if (arg.status){
  235. location.reload();
  236. }else {
  237. alert("")
  238. }
  239. }
  240. })
  241. })
  242. })
  243. })
  244.  
  245. </script>
  246.  
  247. </body>
  248. </html>

teacher.html

  1. #显示
  2. def teacher(request):
  3.  
  4. tk = request.COOKIES.get("ticket")
  5. if not tk:
  6. return redirect("/login/")
  7.  
  8. teacher_list=sqlheper.get_list("""
  9. select teacher.tid as tid,teacher.name,class.title from teacher
  10. left join teacher_class on teacher_class.teacher_id=teacher.tid
  11. left join class on class.cid=teacher_class.class_id""",[])
  12. # print(teacher_list)
  13. result = {}
  14. for row in teacher_list:
  15. tid = row["tid"]
  16. if tid in result:
  17. result[tid]["titles"].append(row["title"])
  18. else:
  19. result[tid] = {"tid":row["tid"],"name":row["name"],"titles":[row["title"],]}
  20.  
  21. return render(request, "teacher.html", {"teacher_list":result.values()})
  22.  
  23. #增加
  24. def get_all_class(request):
  25. import time
  26. time.sleep(1)
  27. obj = sqlheper.SqlHelper()
  28. class_list = obj.get_list('select cid,title from class',[])
  29. obj.close()
  30. return HttpResponse(json.dumps(class_list))
  31.  
  32. def new_teacher(request):
  33.  
  34. ret = {'status': True, 'message': None}
  35. try:
  36. class_list=request.POST.getlist("class_list")
  37. tname=request.POST.get("tname")
  38. teacher_id=sqlheper.get_IncrementId("insert into teacher(name) values(%s)",[tname,])
  39.  
  40. data_list = []
  41. for cls_id in class_list:
  42. temp = (teacher_id,cls_id,)
  43. data_list.append(temp)
  44.  
  45. obj = sqlheper.SqlHelper()
  46. obj.multiple_modify('insert into teacher_class(teacher_id,class_id) values(%s,%s)', data_list)
  47. obj.close()
  48. except Exception as e:
  49. ret['status'] = False
  50. ret['message'] = str(e)
  51. return HttpResponse(json.dumps(ret))
  52.  
  53. #编辑
  54. def edit_tea_cls(request):
  55.  
  56. id = request.POST.get("id")
  57. obj = sqlheper.SqlHelper()
  58. class_list = obj.get_list('select cid,title from class',[])
  59.  
  60. teacher_info = obj.get_one("select tid,name from teacher where tid=%s",[id,])
  61.  
  62. class_id = obj.get_list("select class_id from teacher_class where teacher_id=%s",[id,])
  63.  
  64. data_list = []
  65. for cls_id in class_id:
  66. data_list.append(cls_id["class_id"])
  67.  
  68. print(teacher_info)
  69. total = []
  70. total.append(class_list)
  71. total.append(teacher_info)
  72. total.append(data_list)
  73. obj.close()
  74. return HttpResponse(json.dumps(total))
  75.  
  76. def modal_edit_teacher(request):
  77. ret = {'status': True, 'message': None}
  78. try:
  79. name = request.POST.get("name")
  80. tid = request.POST.get("tid")
  81. class_ids = request.POST.getlist("class_ids")
  82.  
  83. obj = sqlheper.SqlHelper()
  84. obj.modify("update teacher set name=%s where tid=%s", [name, tid, ])
  85. obj.modify('delete from teacher_class where teacher_id=%s', [tid, ])
  86. data_list = []
  87. for cls_id in class_ids:
  88. temp = (tid, cls_id)
  89. data_list.append(temp)
  90. obj.multiple_modify('insert into teacher_class(teacher_id,class_id) values(%s,%s)', data_list)
  91. obj.close()
  92. except Exception as e:
  93. ret['status'] = False
  94. ret['message'] = str(e)
  95. return HttpResponse(json.dumps(ret))

views

Django 学生管理系统的更多相关文章

  1. 饮冰三年-人工智能-Python-26 Django 学生管理系统

    背景:创建一个简单的学生管理系统,熟悉增删改查操作 一:创建一个Django项目(http://www.cnblogs.com/wupeiqi/articles/6216618.html) 1:创建实 ...

  2. Django学生管理系统添加学生时,报错Not Found: /POST

    最近在学习Django,跟着视频写了一个学生系统,主要是增删改查操作,界面丑的一匹 1.url.py from django.contrib import admin from django.urls ...

  3. python Django学生管理

    Django 学生管理系统 1. 一对一 班级  模态增加 编辑 <!DOCTYPE html> <html lang="en"> <head> ...

  4. ORM版,学生管理系统02

    学生管理系统 urls.py url(r'^student_list/$',views.student_list,name="student_list"), url(r'^dele ...

  5. 基于BootStrap,FortAweSome,Ajax的学生管理系统

    一. 基于BootStrap,FortAweSome,Ajax的学生管理系统代码部分 1.students.html <1>html页面文件 <!DOCTYPE html> & ...

  6. Django_学生管理系统

    一. Django简易学生管理系统 1.在pycharm中创建工程student_manage_system,添加app:student_manage 2.配置静态文件:在工程项目目录下新建目录sta ...

  7. 【IOS开发笔记02】学生管理系统

    端到端的机会 虽然现在身处大公司,但是因为是内部创业团队,产品.native.前端.服务器端全部坐在一起开发,大家很容易做零距离交流,也因为最近内部有一个前端要转岗过来,于是手里的前端任务好像可以抛一 ...

  8. C程序范例(2)——学生管理系统”链表“实现

    1.对于学生管理系统,能够实现的方法有许多,但是今天我们用链表的方法来实现.虽然初学者很可能看不懂,但是不要紧,这是要在整体的系统的学习完C语言之后,我才编写出的程序.所以大家不必要担心.在这里与大家 ...

  9. jsp学习之基于mvc学生管理系统的编写

    mvc开发模式:分别是 model层 view层 Control层 在学生管理系统中,model层有学生实体类,数据访问的dao层,view层主要是用于显示信息的界面,Control层主要是servl ...

随机推荐

  1. 一步步教你开发、部署第一个去中心化应用(Dapp) - 宠物商店

    今天我们来编写一个完整的去中心化(区块链)应用(Dapps), 本文可以和编写智能合约结合起来看. 写在前面 阅读本文前,你应该对以太坊.智能合约有所了解,如果你还不了解,建议你先看以太坊是什么除此之 ...

  2. 用session做权限控制

    一个需要用户进行登录的网站,基本上都会设置用户权限,对不同的用户进行权限控制.例如:一个网站肯定会有一个管理员管理着普通的用户,普通的用户不可能对其他用户有着类似于增删改查等操作,这样网站都乱了--, ...

  3. Mycat 分片规则详解--范围取模分片

    实现方式:该算法先进行范围分片,计算出分片组,组内在取模 优点:综合了范围分片和取模分片的优点,分片组内使用取模可以保证组内的数据分布比较均匀,分片组之间采用范围分片可以兼顾范围分片的特点,事先规划好 ...

  4. MYSQL数据库学习五 表的操作和约束

    5.1 表的基本概念 表示包含数据库中所有数据的数据库对象.一行代表唯一的记录,一列代表记录的一个字段. 列(Columns):属性列,创建表时必须指定列名和数据类型. 索引(Indexes):根据指 ...

  5. 【Linux】 文本比较工具 diff和cmp

    Linux 文本比较工具 ■ diff命令 diff用于逐行比较两个文本文件,列出其不同之处 diff [option] <file1> <file2> file1和file2 ...

  6. 如何使用 RESTClient 调试微信支付接口

    我们知道微信支付使用http协议进行api调用,body 使用xml格式,使用的一般http在线调试工具,无法进行xml数据的post. RESTClient 做的很好,支持各种http 方法,bod ...

  7. 2017-2018-1 Java演绎法 第一周 作业

    团队学习:<构建之法> [团队成员]: 学号 姓名 负责工作 20162315 马军 日常统计,项目部分代码 20162316 刘诚昊 项目部分代码,代码质量测试 20162317 袁逸灏 ...

  8. VS2005 与虚拟机的那点事

      好不容易把VS2008装上了,每次F5编译的时候,程序自动退出,意外的是VS2005也是同样的结果.好在有像我一样的好心人,愿意把解决的方法与大家共享.     经过搜索找到了答案,原来是VMwa ...

  9. 团队作业7——第二次项目冲刺(Beta版本12.05-12.07)

    1.当天站立式会议照片 本次会议内容:1:每个人汇报自己完成的工作.2:组长分配各自要完成的任务. 2.每个人的工作 黄进勇:项目整合,后台代码. 李勇:前台界面优化. 何忠鹏:数据库模块. 郑希彬: ...

  10. Python 单向循环链表

    操作 is_empty() 判断链表是否为空 length() 返回链表的长度 travel() 遍历 add(item) 在头部添加一个节点 append(item) 在尾部添加一个节点 inser ...