欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python django+bootstrap4+mysql智慧交通系统构建

程序员文章站 2022-06-22 11:00:31
之前,我做了一个实训的项目,但是一直没有展示如何做的,现在就让我讲解一下如何用django+bootstrap4+mysql实现这个智慧交通系统。这里用到的是网页的bootstrap4框架和mysql数据库。 一:软件项目内容 1.实训项目简介 智慧交通系统是旨在提高员工的日常工作便捷性、工作效率, ......

        之前,我做了一个实训的项目,但是一直没有展示如何做的,现在就让我讲解一下如何用django+bootstrap4+mysql实现这个智慧交通系统。这里用到的是网页的bootstrap4框架和mysql数据库。

 

一:软件项目内容

1.实训项目简介

  智慧交通系统是旨在提高员工的日常工作便捷性、工作效率,降低管理及运营成本的实用项目。本软件系统将为该公司提供车辆信息管理、员工信息管理、线路信息管理、站点信息管理、排班方案管理等功能,同时提供了近场通讯功能(nfc)。利用这些功能充分满足该公交公司日常工作中的管理及信息同步需求。

 

2.用到的uml图

(1)用例图

      首先是需求分析环节,先判断需要的用例,各个外部人员的角色:

   管理员用例,可以管理所有信息:

python django+bootstrap4+mysql智慧交通系统构建

 

   调度员用例,只能操作排班,其他只能查看:

python django+bootstrap4+mysql智慧交通系统构建

 

   

  调度员,只能查看排班信息:

 python django+bootstrap4+mysql智慧交通系统构建

 

 (2)数据流图

数据流图是描绘数据在软件中流动和被处理的逻辑过程的模型。它与数据字典一起用来构成系统的逻辑模型。

总的数据流图:

python django+bootstrap4+mysql智慧交通系统构建

 

 

三层数据流图:

  0层图:

python django+bootstrap4+mysql智慧交通系统构建

 

 

 

   顶层图把数据的流动进行了抽象,泛化。只对管理员和调度人员直接进行了数据流动分析,分为处理事务排班信息和查询排班信息

 

 

   1层图:

python django+bootstrap4+mysql智慧交通系统构建

 

 

  

  1层图对顶层图进行了细分,分为人员信息,车辆信息,线路信息和站点信息管理。

(3)系统功能图

python django+bootstrap4+mysql智慧交通系统构建

 

 

3.数据库设计

(1)er图:

python django+bootstrap4+mysql智慧交通系统构建

 

 (2)概念模型

python django+bootstrap4+mysql智慧交通系统构建

 

(3)物理模型

python django+bootstrap4+mysql智慧交通系统构建

 

 

 

二:django构建智慧交通系统系统

 1.首先我们需要构建一个数据库,这里具体怎么构建就不说了,下面是构建的数据库。

python django+bootstrap4+mysql智慧交通系统构建

 

2.然后我们创建一个django项目,需要修改models.py文件与数据库相对应:
python django+bootstrap4+mysql智慧交通系统构建

修改的代码如下:

from django.db import models


class bus(models.model):
    buscode = models.autofield(db_column='buscode', primary_key=true)  # field name made lowercase.
    buslicense = models.charfield(db_column='buslicense', max_length=20)  # field name made lowercase.
    bustype = models.charfield(db_column='bustype', max_length=25, blank=true, null=true)  # field name made lowercase.
    busstatus = models.charfield(db_column='busstatus', max_length=2, blank=true, null=true)  # field name made lowercase.
    starttime = models.datetimefield(db_column='starttime', blank=true, null=true)  # field name made lowercase.

    class meta:
        managed = true
        db_table = 'bus'


class line(models.model):
    linecode = models.autofield(db_column='linecode', primary_key=true)  # field name made lowercase.
    linename = models.charfield(db_column='linename', max_length=20, blank=true, null=true)  # field name made lowercase.
    status = models.charfield(max_length=2, blank=true, null=true)
    startlinetime = models.datetimefield(db_column='startlinetime', blank=true, null=true)  # field name made lowercase.
    direction = models.charfield(max_length=2, blank=true, null=true)

    class meta:
        managed = true
        db_table = 'line'


class linestationref(models.model):
    linecode = models.foreignkey(line, models.do_nothing, db_column='linecode', blank=true, null=true)  # field name made lowercase.
    stationcode = models.foreignkey('station', models.do_nothing, db_column='stationcode', blank=true, null=true)  # field name made lowercase.
    stationorder = models.integerfield(db_column='stationorder', blank=true, null=true)  # field name made lowercase.

    class meta:
        managed = true
        db_table = 'line_station_ref'


class permission(models.model):
    permissioncode = models.autofield(db_column='permissioncode', primary_key=true)  # field name made lowercase.
    permissionname = models.charfield(db_column='permissionname', max_length=50, blank=true, null=true)  # field name made lowercase.
    permissiondescribe = models.charfield(db_column='permissiondescribe', max_length=100, blank=true, null=true)  # field name made lowercase.

    class meta:
        managed = true
        db_table = 'permission'


class role(models.model):
    rolecode = models.autofield(db_column='rolecode', primary_key=true)  # field name made lowercase.
    rolename = models.charfield(db_column='rolename', max_length=50, blank=true, null=true)  # field name made lowercase.
    roledescribe = models.charfield(max_length=100, blank=true, null=true)

    class meta:
        managed = true
        db_table = 'role'


class rolepermissionref(models.model):
    relationcode = models.autofield(db_column='relationcode', primary_key=true)  # field name made lowercase.
    rolecode = models.foreignkey(role, models.do_nothing, db_column='rolecode', blank=true, null=true)  # field name made lowercase.
    permissioncode = models.foreignkey(permission, models.do_nothing, db_column='permissioncode', blank=true, null=true)  # field name made lowercase.

    class meta:
        managed = true
        db_table = 'role_permission_ref'


class scheduling(models.model):
    code = models.autofield(primary_key=true)
    linecode = models.foreignkey(line, models.do_nothing, db_column='linecode', blank=true, null=true)  # field name made lowercase.
    tcnumber = models.charfield(db_column='tcnumber', max_length=25, blank=true, null=true)  # field name made lowercase.
    tctime = models.charfield(db_column='tctime', max_length=20, blank=true, null=true)  # field name made lowercase.
    usercode = models.foreignkey('sysuser', models.do_nothing, db_column='usercode', blank=true, null=true)  # field name made lowercase.
    startstation = models.foreignkey('station', models.do_nothing, db_column='startstation', blank=true, null=true)  # field name made lowercase.
    endstation = models.foreignkey('station', models.do_nothing, db_column='endstation', blank=true, null=true,related_name='endstation')  # field name made lowercase.
    buslicense = models.foreignkey(bus, models.do_nothing, db_column='buslicense', blank=true, null=true)  # field name made lowercase.

    class meta:
        managed = true
        db_table = 'scheduling'


class station(models.model):
    stationcode = models.autofield(db_column='stationcode', primary_key=true)  # field name made lowercase.
    stationname = models.charfield(db_column='stationname', max_length=50, blank=true, null=true)  # field name made lowercase.
    longitude = models.charfield(max_length=50, blank=true, null=true)
    latitude = models.charfield(max_length=50, blank=true, null=true)
    region = models.charfield(max_length=50, blank=true, null=true)
    street = models.charfield(max_length=50, blank=true, null=true)

    class meta:
        managed = true
        db_table = 'station'


class sysuser(models.model):
    code = models.autofield(primary_key=true)
    loginname = models.charfield(db_column='loginname', max_length=25, blank=true, null=true)  # field name made lowercase.
    password = models.charfield(max_length=50, blank=true, null=true)
    name = models.charfield(max_length=25, blank=true, null=true)
    phone = models.charfield(max_length=11, blank=true, null=true)
    idcard = models.charfield(db_column='idcard', max_length=25, blank=true, null=true)  # field name made lowercase.
    role = models.foreignkey(role,models.do_nothing, db_column='role', blank=true, null=true)
    driving = models.decimalfield(max_digits=10, decimal_places=0, blank=true, null=true)
    status = models.charfield(max_length=25, blank=true, null=true)

    class meta:
        managed = true
        db_table = 'sysuser'

 

3.然后我们创建如下的静态网页文件,分别代表不同功能:
python django+bootstrap4+mysql智慧交通系统构建

 

4.登录页面

首先是需要构建登录页面,代码如下:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>用户登录</title>
  <link rel="stylesheet" type="text/css" href="/static/css/denglu.css" />
  <script src="/static/js/jquery.js"> </script>
  <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.css">
  <script src="/static/bootstrap/js/bootstrap.js"></script>
</head>

<body>
    <!-- 两个输入框 -->
    <div class="container">
        <div class="row row-centered">
            <div class="col-xs-6 col-md-4 col-center-block" id="one">
                <h1 class="textcolor">智慧交通</h1>
                <h3 class="textcolor">公交调度排班系统</h3>
                <form action="{%url 'denglu' %}" method="post">
{#                  csrf_token 是为了防止csrf(跨站请求伪造),安全机制去,需要加上#}
                    {%csrf_token%}
                    <!-- 输入登录名 -->
                    <div class="input-group input-group-md">
                        <span class="input-group-addon" id="sizing-addon1">
                            <i class="glyphicon glyphicon-user" aria-hidden="true"></i></span>
                        <input type="text" class="form-control" id="userid" name="username" placeholder="请输入登录名"/>
                    </div>
                    <!-- 输入密码 -->
                    <div class="edit input-group input-group-md">
                        <span class="input-group-addon" id="sizing-addon2">
                            <i class="glyphicon glyphicon-lock"></i></span>
                        <input type="password" class="form-control" id="userpassword" name="userpassword" placeholder="请输入密码"/>
                    </div>
                    <br/>

                    <button type="submit" class="btn btn-primary btn-block" name="submit" value="登录">登录</button>

                    <button type="submit" class="btn btn-success btn-block" name="submit" value="登录">清空</button>
                    
                </form>
            </div>
        </div>
    </div>
</body>
</html>

想{%url 'denglu' %}这样的写法就是为了和后台交互的,然后我们用denglu变量和后台交互,在urls.py中加入如下代码:

re_path(r'^$',view.denglu),
#登录后接受表单跳转页面
path('tiao_zhuan',view.getdenglu,name="denglu"),

这时候只是显示登陆后的状态,并没有具体操作,就需要在view.py文件中加入下面的代码进行动态交互:

def denglu(request):
    # 登陆管理
    return render(request, "denglu.html")

def getdenglu(request):
    # 用户登录后跳转页面
    username = request.post.get("username")
    userpassword = request.post.get("userpassword")
    response = sysuser.objects.filter(loginname=username,password=userpassword)
    if response:
        for i in response:
            quan_xian = i.role.rolecode
            zhuang_tai = i.status
            if quan_xian == 0:
                return render(request, "index.html")
            if quan_xian == 1 and zhuang_tai == '启动':
                schedul_list = scheduling.objects.all()
                return render(request,"form_basic_diao_du.html",{"schedul_list":schedul_list})
            elif quan_xian == 2 and zhuang_tai == '启动':
                schedul_list = scheduling.objects.all()
                return render(request, "form_basic_look.html",{"schedul_list":schedul_list})
    else:
        return 0

然后就可以看到我们的页面:
python django+bootstrap4+mysql智慧交通系统构建

这里就根据数据库中的用户表进行判断:

python django+bootstrap4+mysql智慧交通系统构建

 

5.其他页面构建

其他的比如员工,车辆,站点,排班信息和的增删查改网页代码这里只举一例:

<!-- 增加窗口 -->
    <div id="register" class="modal fade" tabindex="-1">
        <div class="modal_wrapper">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button class="close" data-dismiss="modal">
                            <span>×</span>
                        </button>
                    </div>
                    <div class="modal-title">
                        <h1 class="text-center">增加员工信息</h1>
                    </div>
                    <div action="index" class="modal-body">
                        <form action="{%url 'form' %}" method="post">
{#                            csrf_token 是为了防止csrf(跨站请求伪造),安全机制去,需要加上#}
                            {%csrf_token%}
                            <!-- 输入用户编号 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-star"></i></span>
                                <input class="form-control" id="code" name="code" placeholder="请输入用户编号"/>
                            </div>
                            <!-- 输入登录名 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-user"></i></span>
                                <input class="form-control" id="loginname" name="loginname" placeholder="请输入登录名"/>
                            </div>
                            <!-- 输入登录密码 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-ok"></i></span>
                                <input class="form-control" id="password" name="password" placeholder="请输入登录密码"/>
                            </div>
                            <!-- 输入姓名 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-euro"></i></span>
                                <input class="form-control" id="name" name="name" placeholder="请输入姓名"/>
                            </div>
                            <!-- 输入手机号 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-phone-alt"></i></span>
                                <input class="form-control" id="phone" name="phone" placeholder="请输入手机号"/>
                            </div>
                            <!-- 输入身份证 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-list-alt"></i></span>
                                <input class="form-control" id="idcard" name="idcard" placeholder="请输入身份证"/>
                            </div>
                            <div class="form-group">
                                <label for="sel1">输入状态</label>
                                <select class="form-control" id="driving" name="status">
                                <option value="启动">启动</option>
                                <option value="禁用">禁用</option>
                                </select>
                            </div>
                            <!-- 输入角色 -->
                            <div class="form-group">
                                <label for="sel1">输入角色</label>
                                <select class="form-control" id="status" name="role">
                                <option value="管理员">管理员</option>
                                <option value="调度员">调度员</option>
                                <option value="驾驶员">驾驶员</option>
                                </select>
                            </div>
                            <!-- 输入驾龄 -->
                            <input class="form-control" id="thisinput" name="driving" placeholder="请输入驾龄"/>
                            <br/>
                            <button type="submit" class="btn btn-success btn-block" name="submit" value="增加">增加并保存</button>
                            <button class="btn btn-primary btn-block" data-dismiss="modal">返回</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

        <!-- 删除窗口 -->
    <div id="delete" class="modal fade" tabindex="-1">
        <div class="modal_wrapper">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button class="close" data-dismiss="modal">
                            <span>×</span>
                        </button>
                    </div>
                    <div class="modal-title">
                        <h1 class="text-center">请选择要删除的用户编号</h1>
                    </div>
                    <div action="" class="modal-body">
                        <form action="{%url 'form2' %}" method="post">
{#                             csrf_token 是为了防止csrf(跨站请求伪造),安全机制去,需要加上#}
                            {%csrf_token%}
                            <!-- 输入用户编号 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-star"></i></span>
                                <input class="form-control" id="my_delete" name="my_delete" placeholder="请输入要删除的用户编号"/>
                            </div>
                            <button type="submit" class="btn btn-success btn-block" name="submit" value="增加">确定删除</button>
                            <button class="btn btn-primary btn-block" data-dismiss="modal">返回</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>


        <!-- 修改窗口 -->
    <div id="modify" class="modal fade" tabindex="-1">
        <div class="modal_wrapper">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <button class="close" data-dismiss="modal">
                            <span>×</span>
                        </button>
                    </div>
                    <div class="modal-title">
                        <h1 class="text-center">修改员工信息</h1>
                    </div>
                    <div action="index" class="modal-body">
                        <form action="{%url 'form3' %}" method="post">
{#                            csrf_token 是为了防止csrf(跨站请求伪造),安全机制去,需要加上#}
                            {%csrf_token%}
                            <!-- 输入用户编号 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-star"></i></span>
                                <input class="form-control" id="code" name="code" placeholder="请输入要修改的用户编号"/>
                            </div>
                            <!-- 输入修改后的编号 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-star"></i></span>
                                <input class="form-control" id="code2" name="code2" placeholder="请输入修改后的用户编号"/>
                            </div>
                            <!-- 输入登录名 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-user"></i></span>
                                <input class="form-control" id="loginname" name="loginname" placeholder="请输入修改后的登录名"/>
                            </div>
                            <!-- 输入登录密码 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-ok"></i></span>
                                <input class="form-control" id="password" name="password" placeholder="请输入修改后的登录密码"/>
                            </div>
                            <!-- 输入姓名 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-euro"></i></span>
                                <input class="form-control" id="name" name="name" placeholder="请输入修改后的姓名"/>
                            </div>
                            <!-- 输入手机号 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-phone-alt"></i></span>
                                <input class="form-control" id="phone" name="phone" placeholder="请输入修改后的手机号"/>
                            </div>
                            <!-- 输入身份证 -->
                            <div class="edit input-group input-group-md">
                            <span class="input-group-addon">
                                <i class="glyphicon glyphicon-list-alt"></i></span>
                                <input class="form-control" id="idcard" name="idcard" placeholder="请输入修改后的身份证"/>
                            </div>
                            <div class="form-group">
                                <label for="sel1">输入状态</label>
                                <select class="form-control" id="driving" name="status">
                                <option value="启动">启动</option>
                                <option value="禁用">禁用</option>
                                </select>
                            </div>
                            <!-- 输入角色 -->
                            <div class="form-group">
                                <label for="sel1">输入角色</label>
                                <select class="form-control" id="status2" name="role">
                                <option value="管理员">管理员</option>
                                <option value="调度员">调度员</option>
                                <option value="驾驶员">驾驶员</option>
                                </select>
                            </div>
                            <!-- 输入驾龄 -->
                            <input class="form-control" id="thisinput2" name="driving" placeholder="请输入驾龄"/>
                            <br/>
                            <button type="submit" class="btn btn-success btn-block" name="submit" value="修改">修改并保存</button>
                            <button class="btn btn-primary btn-block" data-dismiss="modal">返回</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

 

6.所有的urls.py文件内容如下:

from django.urls import path,re_path
from . import view

urlpatterns = [
    # 两个必选参数:route、view 和两个可选参数:kwargs、name
    # route: 字符串,表示 url 规则,与之匹配的 url 会执行对应的第二个参数 view。
    # view: 用于执行与正则表达式匹配的 url 请求。
    # kwargs: 视图使用的字典类型的参数。
    # name: 用来反向获取 url。
    # path('', view.hello),

    # django >= 2.0 的版本,urls.py的django.conf.urls已经被django.urls取代
    # django >= 2.0 的版本,path() 函数无法匹配正则表达式,需要使用 re_path() 即可匹配正则表达式
    # 首页
    re_path(r'^$',view.denglu),

    # 登录后接受表单跳转页面
    path('tiao_zhuan',view.getdenglu,name="denglu"),

    # 选择其他按钮后跳转页面
    path('denglu',view.denglu,name="deng_lu"),
    path('index',view.index,name='index'),
    path('che_liang',view.che_liang,name='che_liang'), # 这里设置name,为了在模板文件中,写name,就能找到这个路由
    path('zhan_dian',view.zhan_dian,name='zhan_dian'),
    path('xian_lu',view.xian_lu,name='xian_lu'),
    path('graph_flot',view.graph_flot,name='graph_flot'),
    path('form_basic',view.form_basic,name='form_basic'),
    path('table_basic',view.table_basic,name='table_basic'),
    # 员工
    path('my_index',view.save_user,name="form"),
    path('my_delete',view.delete_user,name="form2"),
    path('my_modify',view.modify_user,name="form3"),
    path('index_find',view.chaxun_user,name="form4"),
    # 车辆
    path('che_liang_index',view.che_save,name="che_liang_form"),
    path('che_liang_delete',view.che_delete,name="che_liang_form2"),
    path('che_liang_modify',view.che_modify,name="che_liang_form3"),
    path('che_liang_find',view.chaxun_che,name="che_liang_form4"),
    # 站点
    path('zhan_dian_index',view.zhan_dian_save,name="zhan_dian_form"),
    path('zhan_dian_delete',view.zhan_dian_delete,name="zhan_dian_form2"),
    path('zhan_dian_modify',view.zhan_dian_modify,name="zhan_dian_form3"),
    path('zhan_dian_find',view.chaxun_zhan_dian,name="zhan_dian_form4"),
    # 线路
    path('xian_lu_index',view.xian_lu_save,name="xian_lu_form"),
    path('xian_lu_delete',view.xian_lu_delete,name="xian_lu_form2"),
    path('xian_lu_modify',view.xian_lu_modify,name="xian_lu_form3"),
    path('xian_lu_find',view.chaxun_xian_lu,name="xian_lu_form4"),
    # 排班
    path("pai_ban_index",view.pai_ban_save,name="pai_ban_form"),
    path("pai_ban_delete",view.pai_ban_delete,name="pai_ban_form2"),
    path("pai_ban_modify",view.pai_ban_modify,name="pai_ban_form3"),
    path("form_basic_find",view.chaxun_pai_ban,name="pai_ban_form4"),
]

 

7.所有的view.py文件如下:

from django.shortcuts import render
from shujuku.models import *


def denglu(request):
    # 登陆管理
    return render(request, "denglu.html")

def getdenglu(request):
    # 用户登录后跳转页面
    username = request.post.get("username")
    userpassword = request.post.get("userpassword")
    response = sysuser.objects.filter(loginname=username,password=userpassword)
    if response:
        for i in response:
            quan_xian = i.role.rolecode
            zhuang_tai = i.status
            if quan_xian == 0:
                return render(request, "index.html")
            if quan_xian == 1 and zhuang_tai == '启动':
                schedul_list = scheduling.objects.all()
                return render(request,"form_basic_diao_du.html",{"schedul_list":schedul_list})
            elif quan_xian == 2 and zhuang_tai == '启动':
                schedul_list = scheduling.objects.all()
                return render(request, "form_basic_look.html",{"schedul_list":schedul_list})
    else:
        return 0


def index(request):
    # 用户表管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = sysuser.objects.all()
    return render(request,"index.html",{"user_list": my_list})


def che_liang(request):
    # 车辆表管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = bus.objects.all()
    return render(request, 'che_liang.html',{"cheliang_list": my_list})


def zhan_dian(request):
    # 站点表管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = station.objects.all()
    return render(request, 'zhan_dian.html',{"zhandian_list":my_list})


def xian_lu(request):
    # 线路表管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = line.objects.all()
    a = {}
    for i in my_list:
        my_linecode = i.linecode
        response = linestationref.objects.filter(linecode=my_linecode)
        b = []
        for j in response:
            b.append(j.stationcode.stationname)
        a[my_linecode] = b
    return render(request, 'xian_lu.html',{"xianlu_list":my_list,"a":a})


def graph_flot(request):
    # 基础数据管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = role.objects.all()
    my_list2 = permission.objects.all()
    return render(request, 'graph_flot.html',{"role_list":my_list,"primission":my_list2})


def form_basic(request):
    # 排班表管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = scheduling.objects.all()
    return render(request, 'form_basic.html',{"schedul_list":my_list})


def table_basic(request):
    # 关系数据管理
    # 通过objects这个模型管理器的all()获得所有数据行,相当于sql中的select * from
    my_list = rolepermissionref.objects.all()
    my_list2 = linestationref.objects.all()
    return render(request, 'table_basic.html',{"guanxi_list":my_list,"guanxi2_list":my_list2})


# 处理表单
# 接收post请求数据

# 用户操作
def save_user(request):
    all_list = {}
    # 保存员工信息增加数据
    if request.method == 'post':
        code = request.post.get('code')
        loginname = request.post.get('loginname')
        password = request.post.get('password')
        name = request.post.get('name')
        phone = request.post.get('phone')
        idcard = request.post.get('idcard')
        role = request.post.get('role')
        driving = request.post.get('driving')
        status = request.post.get('status')
        if driving=='':
            driving = 0
        my_role = role.objects.filter(rolename=role)
        for i in my_role:
            user = sysuser(code=code,loginname=loginname,password=password,name=name,phone=phone,idcard=idcard,
                       role=i,driving=driving,status=status)
            user.save()
        all_list = {"code":code, "loginname":loginname, "password":password, "name":name,
                       "phone":phone, "idcard":idcard, "driving":driving,"status":status,"role":role}
    return render(request,'my_index.html',{"user_list2":all_list})


def delete_user(request):
    all_list = {}
    # 删除员工信息
    if request.method == 'post':
        aa = request.post.get("my_delete")
        sysuser.objects.filter(code=aa).delete()
    return render(request, 'index.html')


def modify_user(request):
    # 修改员工信息
    if request.method == 'post':
        code = request.post.get('code')
        code2 = request.post.get('code2')
        loginname = request.post.get('loginname')
        password = request.post.get('password')
        name = request.post.get('name')
        phone = request.post.get('phone')
        idcard = request.post.get('idcard')
        role = request.post.get('role')
        driving = request.post.get('driving')
        status = request.post.get('status')
        if driving=='':
            driving = 0
        my_role = role.objects.filter(rolename=role)
        for i in my_role:
            sysuser.objects.filter(code=code).update(code=code2,loginname=loginname,password=password,
                             role=i,name=name,phone=phone,idcard=idcard,driving=driving,status=status)
    return render(request, 'index.html')


def chaxun_user(request):
    if request.method == 'post':
        one = request.post.get('one')
        two = request.post.get('two')
        response = sysuser.objects.filter(loginname=one,status=two)
        return render(request,'index_find.html',{'find_user_list':response})




# 车辆操作
def che_save(request):
    all_list = {}
    # 保存车辆信息增加数据
    if request.method == 'post':
        buscode = request.post.get('buscode')
        buslicense = request.post.get('buslicense')
        bustype = request.post.get('bustype')
        busstatus = request.post.get('busstatus')
        starttime = request.post.get('starttime')
        this_bus = bus(buscode=buscode,buslicense=buslicense,bustype=bustype,busstatus=busstatus,
                       starttime=starttime)
        this_bus.save()
    return render(request,'che_liang.html')


def che_delete(request):
    all_list = {}
    # 删除车辆信息
    if request.method == 'post':
        aa = request.post.get("my_delete")
        bus.objects.filter(buscode=aa).delete()
    return render(request, 'che_liang.html')


def che_modify(request):
    all_list = {}
    # 修改车辆信息
    if request.method == 'post':
        buscode = request.post.get('buscode')
        buscode2 = request.post.get('buscode2')
        buslicense = request.post.get('buslicense')
        bustype = request.post.get('bustype')
        busstatus = request.post.get('busstatus')
        starttime = request.post.get('starttime')
        bus.objects.filter(buscode=buscode).update(buscode=buscode2,buslicense=buslicense,bustype=bustype,busstatus=busstatus,
                       starttime=starttime)
    return render(request,'che_liang.html')

def chaxun_che(request):
    if request.method == 'post':
        one = request.post.get('one')
        two = request.post.get('two')
        response = bus.objects.filter(buslicense=one,busstatus=two)
        return render(request,'che_liang_find.html',{'find_user_list':response})




# 站点
def zhan_dian_save(request):
    all_list = {}
    # 保存站点信息增加数据
    if request.method == 'post':
        stationcode = request.post.get('stationcode')
        stationname = request.post.get('stationname')
        longitude = request.post.get('longitude')
        latitude = request.post.get('latitude')
        region = request.post.get('region')
        street = request.post.get('street')
        this_zhan_dian = station(stationcode=stationcode,stationname=stationname,longitude=longitude,
                                 latitude=latitude,region=region,street=street)
        this_zhan_dian.save()
    return render(request,'zhan_dian.html')

def zhan_dian_delete(request):
    all_list = {}
    # 删除站点信息
    if request.method == 'post':
        aa = request.post.get("my_delete")
        station.objects.filter(stationcode=aa).delete()
    return render(request, 'zhan_dian.html')

def zhan_dian_modify(request):
    all_list = {}
    # 修改站点信息
    if request.method == 'post':
        stationcode = request.post.get('stationcode')
        stationcode2 = request.post.get('stationcode2')
        stationname = request.post.get('stationname')
        longitude = request.post.get('longitude')
        latitude = request.post.get('latitude')
        region = request.post.get('region')
        street = request.post.get('street')
        station.objects.filter(stationcode=stationcode).update(stationcode=stationcode2,stationname=stationname,longitude=longitude,
                                 latitude=latitude,region=region,street=street)
    return render(request,'zhan_dian.html')

def chaxun_zhan_dian(request):
    if request.method == 'post':
        one = request.post.get('one')
        two = request.post.get('two')
        three = request.post.get('three')
        response = station.objects.filter(stationname=one,region=two,street=three)
        return render(request,'zhan_dian_find.html',{'find_user_list':response})




# 线路
def xian_lu_save(request):
    all_list = {}
    # 保存线路信息增加数据
    if request.method == 'post':
        linecode = request.post.get('linecode')
        linename = request.post.get('linename')
        status = request.post.get('status')
        startlinetime = request.post.get('startlinetime')
        direction = request.post.get('direction')
        xian_lu_dian = line(linecode=linecode,linename=linename,status=status,
                                 startlinetime=startlinetime,direction=direction)
        xian_lu_dian.save()
    return render(request,'xian_lu.html')

def xian_lu_delete(request):
    all_list = {}
    # 删除线路信息
    if request.method == 'post':
        aa = request.post.get("my_delete")
        line.objects.filter(linecode=aa).delete()
    return render(request, 'xian_lu.html')

def xian_lu_modify(request):
    all_list = {}
    # 修改线路信息
    if request.method == 'post':
        linecode = request.post.get('linecode')
        linecode2 = request.post.get('linecode2')
        linename = request.post.get('linename')
        status = request.post.get('status')
        startlinetime = request.post.get('startlinetime')
        direction = request.post.get('direction')
        xian_lu_dian = line.objects.filter(linecode=linecode).update(linecode2=linecode2,linename=linename,status=status,
                                 startlinetime=startlinetime,direction=direction)
        xian_lu_dian.save()
    return render(request,'xian_lu.html')

def chaxun_xian_lu(request):
    if request.method == 'post':
        one = request.post.get('one')
        two = request.post.get('two')
        three = request.post.get('three')
        response = line.objects.filter(linename=one,direction=two,status=three)
        print(response)
        return render(request,'xian_lu_find.html',{'find_user_list':response})




# 排班
def pai_ban_save(request):
    # 保存排班信息增加数据
    all_list1 = {}  # 存储线路编号
    all_list2 = {}  # 存储车牌号
    all_list3 = {}  # 存储司机编号
    all_list4 = {}  # 存储始发站
    all_list5 = {}  # 存储终点站

    for i in line.objects.all():
        all_list1[i] = i.linecode

    for i in bus.objects.all():
        # 判断汽车是否启运
        if i.busstatus == '启运':
            all_list2[i] = i.buslicense
        else:
            continue


    for i in sysuser.objects.all():
        # 判断是否为司机
        k = i.role.rolecode
        if k == 2:
            all_list3[i] = i.code
        else:
            continue


    for i in station.objects.all():
        all_list4[i] = i.stationname

    for i in station.objects.all():
        all_list5[i] = i.stationname

    if request.method == 'post':
        code = request.post.get('code')
        linecode = request.post.get('linecode')
        buslicense = request.post.get('buslicense')
        tcnumber = request.post.get('tcnumber')
        tctime = request.post.get('tctime')
        usercode = request.post.get('usercode')
        startstation = request.post.get('startstation')
        endstation = request.post.get('endstation')

        user = scheduling(code=code)
        # 线路编号
        linecode = line.objects.filter(linecode=linecode)
        for i in linecode:
            user.linecode = i

        # 车牌号
        buslicense = bus.objects.filter(buslicense=buslicense)
        for i in buslicense:
            user.buslicense = i

        # 趟次
        user.tcnumber = tcnumber
        # 每趟时间
        user.tctime = tctime

        # 司机编号
        usercode = sysuser.objects.filter(code=usercode)
        for i in usercode:
            user.usercode = i

        # 始发站
        startstation = station.objects.filter(stationname=startstation)
        for i in startstation:
            user.startstation = i

        # 终点站
        endstation = station.objects.filter(stationname=endstation)
        for i in endstation:
            user.endstation = i

        user.save()

    return render(request,'form_basic.html',{"linecode":all_list1,"buslicense":all_list2,"usercode":all_list3,
                    "startstation":all_list4,"endstation":all_list5})


def pai_ban_delete(request):
    all_list = {}
    # 删除排班信息
    if request.method == 'post':
        aa = request.post.get("my_delete")
        scheduling.objects.filter(code=aa).delete()
    return render(request, 'form_basic.html')


def pai_ban_modify(request):
    # 修改排班信息
    all_list1 = {}  # 存储线路编号
    all_list2 = {}  # 存储车牌号
    all_list3 = {}  # 存储司机编号
    all_list4 = {}  # 存储始发站
    all_list5 = {}  # 存储终点站

    for i in line.objects.all():
        all_list1[i] = i.linecode

    for i in bus.objects.all():
        # 判断汽车是否启运
        if i.busstatus == '启运':
            all_list2[i] = i.buslicense
        else:
            continue


    for i in sysuser.objects.all():
        # 判断是否为司机
        k = i.role.rolecode
        if k == 2:
            all_list3[i] = i.code
        else:
            continue


    for i in station.objects.all():
        all_list4[i] = i.stationname

    for i in station.objects.all():
        all_list5[i] = i.stationname

    if request.method == 'post':
        code = request.post.get('code')
        code2 = request.post.get('code2')
        linecode = request.post.get('linecode')
        buslicense = request.post.get('buslicense')
        tcnumber = request.post.get('tcnumber')
        tctime = request.post.get('tctime')
        usercode = request.post.get('usercode')
        startstation = request.post.get('startstation')
        endstation = request.post.get('endstation')

        user = scheduling.objects.filter(code=code).update(code=code2)


        # 线路编号
        linecode = line.objects.filter(linecode=linecode)
        for i in linecode:
            user.linecode = i

        # 车牌号
        buslicense = bus.objects.filter(buslicense=buslicense)
        for i in buslicense:
            user.buslicense = i

        # 趟次
        user.tcnumber = tcnumber
        # 每趟时间
        user.tctime = tctime

        # 司机编号
        usercode = sysuser.objects.filter(code=usercode)
        for i in usercode:
            user.usercode = i

        # 始发站
        startstation = station.objects.filter(stationname=startstation)
        for i in startstation:
            user.startstation = i

        # 终点站
        endstation = station.objects.filter(stationname=endstation)
        for i in endstation:
            user.endstation = i

        user.save()
    return render(request,'form_basic.html',{"linecode":all_list1,"buslicense":all_list2,"usercode":all_list3,
                    "startstation":all_list4,"endstation":all_list5})


def chaxun_pai_ban(request):
    if request.method == 'post':
        one = request.post.get('one')
        two = request.post.get('two')
        three = request.post.get('three')
        response = scheduling.objects.filter(code=one,tcnumber=two,tctime=three)
        return render(request,'form_basic_find.html',{'schedul_list2':response})

 

三:运行结果如下:

1.登录管理员页面

python django+bootstrap4+mysql智慧交通系统构建

 

 

2.调度员登录,只可以修改排班信息

python django+bootstrap4+mysql智慧交通系统构建

 

3.驾驶员登录,只能查看排班信息

python django+bootstrap4+mysql智慧交通系统构建

 

4.员工信息管理这里就不展示了,下面展示排班管理

(1)增加排班信息

python django+bootstrap4+mysql智慧交通系统构建

修改后的展示为:
python django+bootstrap4+mysql智慧交通系统构建

发现可以选择了。

(2)删除排班信息

python django+bootstrap4+mysql智慧交通系统构建

(3)修改排班信息

python django+bootstrap4+mysql智慧交通系统构建

 

5.基础信息查看

python django+bootstrap4+mysql智慧交通系统构建