Python CRM项目二

小说:求购紫穗槐小苗去哪里好?作者:开陵更新时间:2019-04-21字数:45468

一.准备工作

如果没有配置基本的项目,请参考 http://www.cnblogs.com/luhuajun/p/7771196.html

当我们配置完成后首先准备我们的app

创建2个app分别对应学生,重写的Admin模板

1 python manager.py startapp student  #学生视图
2 python manager.py startapp king_admin #king_admin视图
View Code

配置每个app的url映射

1.主app

1 #将每个模块的urls.py引入
2 urlpatterns = [
3     url(r"^admin/", admin.site.urls),
4     url(r"^crm/",include("crm.urls")),
5     url(r"^student/",include("student.urls")),
6     url(r"^king_admin/",include("king_admin.urls")),
7 ]
View Code

2.crm

1 urlpatterns = [
2     url(r"^$",views.index,name="sales_index"),#销售首页
3     url(r"customers/",views.customer_list,name="customer_list"),#客户库
4 ]
View Code

3.student

1 urlpatterns = [
2     #学生首页   
3     url(r"^$",views.index,name="stu_index"),
4 ]
View Code

4.king_admin

1 urlpatterns = [
2     #表首页
3     url(r"^$",views.index,name="table_index"),
4 ]
View Code

配置每个url的视图

1.crm

1 def index(request):
2     #返回销售首页
3     return render(request,"index.html",name="sales_index")
4 
5 
6 def customer_list(request):
7     #返回客户库首页
8     return render(request,"sales/customers.html")
View Code

2.student

1 def index(request):
2     #返回学生首页
3     return render(request,"student/index.html")
View Code

3.king_admin

1 def index(request):
2     #返回表格管理页面
3     return render(request, "king_admin/table_index.html",{"table_list":king_admin.enabled_admins})
View Code

配置前端页面

模板使用:http://v3.bootcss.com/examples/dashboard/

将上面的模板下载,将css,js,文件按一下的层级结构归类

下载的html文件进行分解,分解为base.html和index.html

base.html存放css文件和js文件

index.html继承base.html然后在此基础上进行定制

base.html

 1 <!DOCTYPE html>
 2 <html lang="zh-CN">
 3   <head>
 4     <meta charset="utf-8">
 5     <meta http-equiv="X-UA-Compatible" content="IE=edge">
 6     <meta name="viewport" content="width=device-width, initial-scale=1">
 7     <!-- 上述3个meta标签*必须*放在最前面,任何其他内容都*必须*跟随其后! -->
 8     <meta name="description" content="">
 9     <meta name="author" content="">
10 
11 
12     <title>oldboy CRM</title>
13 
14     <!-- Bootstrap core CSS -->
15     <link href="/static/css/bootstrap.min.css" rel="stylesheet">
16 
17     <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
18     <link href="/static/css/dashboard.css" rel="stylesheet">
19 
20     <!-- Custom styles for this template -->
21     <link href="/static/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
22     <link href="/static/plugins/dropzone/dropzone.css" rel="stylesheet">
23 
24     {% block css %}{% endblock %}
25 
26 
27   </head>
28 
29   {% block body %}{% endblock %}
30 
31 
32     <script src="/static/js/jquery.min.js"></script>
33     <script src="/static/js/bootstrap.min.js"></script>
34     <script src="/static/js/holder.min.js"></script>
35     <script src="/static/js/ie10-viewport-bug-workaround.js"></script>
36     <script src="/static/plugins/dropzone/dropzone.js"></script>
37   {% block bottom-js %}{% endblock %}
38 </html>
View Code

index.html

 1 {% extends "base.html" %}
 2 {% block body %}
 3 <body>
 4     <nav class="navbar navbar-inverse navbar-fixed-top">
 5       <div class="container-fluid">
 6         <div class="navbar-header">
 7           <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
 8             <span class="sr-only">Toggle navigation</span>
 9             <span class="icon-bar"></span>
10             <span class="icon-bar"></span>
11             <span class="icon-bar"></span>
12           </button>
13           <a class="navbar-brand" href="#">My CRM</a>
14         </div>
15         <div id="navbar" class="navbar-collapse collapse">
16           <ul class="nav navbar-nav navbar-right">
17 
18 
19             <li class="dropdown">
20                 <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">{{ request.user }}</a>
21                 <ul class="dropdown-menu" role="menu">
22 {#                    <li><a href="{% url "acc_logout" %}">注销</a></li>#}
23                 </ul>
24             </li>
25           </ul>
26 
27         </div>
28       </div>
29     </nav>
30 
31     <div class="container-fluid">
32       <div class="row">
33         <div class="col-sm-3 col-md-2 sidebar">
34           <ul class="nav nav-sidebar">
35 {#            {% for role in request.user.roles.all %}#}
36 {#                {% for menu in role.menus.all %}#}
37 {#                    <li><a href="{% if menu.url_type == 0 %}{% url menu.url_name %}{% else %}{{   menu.url_name }}{% endif %}">{{ menu.name }}</a></li>#}
38 {#                {% endfor %}#}
39 {#            {% endfor %}#}
40               {% for role in request.user.userprofile.roles.all %}
41                 {% for menu in role.menus.all %}
42                     <li><a href="{% url menu.url_name %}">{{ menu.name }}</a></li>
43                 {% endfor %}
44               {% endfor %}
45           </ul>
46 
47         </div>
48         <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
49            {% block page-content %}
50             <h1 class="page-header">Dashboard</h1>
51             <div class="row placeholders">
52             <div class="col-xs-6 col-sm-3 placeholder">
53               <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
54               <h4>Label</h4>
55               <span class="text-muted">Something else</span>
56             </div>
57             <div class="col-xs-6 col-sm-3 placeholder">
58               <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
59               <h4>Label</h4>
60               <span class="text-muted">Something else</span>
61             </div>
62             <div class="col-xs-6 col-sm-3 placeholder">
63               <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
64               <h4>Label</h4>
65               <span class="text-muted">Something else</span>
66             </div>
67             <div class="col-xs-6 col-sm-3 placeholder">
68               <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
69               <h4>Label</h4>
70               <span class="text-muted">Something else</span>
71             </div>
72           </div>
73 
74 
75             <h2 class="sub-header">Section title</h2>
76             {% endblock %}
77         </div>
78       </div>
79 
80     </div>
81   </body>
82 {% endblock %}
View Code

然后在template下创个各个app名称的文件夹来存放不同app的页面,目录结构如下

 

 然后启动项目,看看每个url是否可以正常访问

准备数据

在插入数据之前,由于本项目要是用动态菜单,所以还要创建一张菜单表和角色表进行关联

 1 class Menu(models.Model):
 2     """菜单表"""
 3     name = models.CharField(max_length=32)
 4     url_name = models.CharField(max_length=64,unique=True)
 5 
 6     def __str__(self):
 7         return self.name
 8     class Meta:
 9         verbose_name_plural = "菜单"
10 
11 
12 class Role(models.Model):
13     """角色表"""
14     name = models.CharField(max_length=64,unique=True)
15     #新增菜单信息
16     menus = models.ManyToManyField("Menu",blank=True)
17     def __str__(self):
18         return self.name
19 
20     class Meta:
21         verbose_name_plural = "角色"
View Code

同步数据库,启动项目,进入admin后台管理

在一些表中插入数据

首先插入tag表

1 INSERT INTO prefect_crm.crm_tag (name) VALUES ("土豪");
2 INSERT INTO prefect_crm.crm_tag (name) VALUES ("屌丝");
3 INSERT INTO prefect_crm.crm_tag (name) VALUES ("无基础");
4 INSERT INTO prefect_crm.crm_tag (name) VALUES ("有基础");
5 INSERT INTO prefect_crm.crm_tag (name) VALUES ("有工作经验");
6 INSERT INTO prefect_crm.crm_tag (name) VALUES ("没文化");
7 INSERT INTO prefect_crm.crm_tag (name) VALUES ("没有工作经验");
8 INSERT INTO prefect_crm.crm_tag (name) VALUES ("转行");
View Code

菜单表

1 INSERT INTO prefect_crm.crm_menu (name, url_name) VALUES ("销售首页", "sales_index");
2 INSERT INTO prefect_crm.crm_menu (name, url_name) VALUES ("学生首页", "stu_index");
3 INSERT INTO prefect_crm.crm_menu (name, url_name) VALUES ("客户库", "customer_list");
View Code

角色表

1 INSERT INTO prefect_crm.crm_role (name) VALUES ("学生");
2 INSERT INTO prefect_crm.crm_role (name) VALUES ("销售");
View Code

角色和菜单的关联表

1 INSERT INTO prefect_crm.crm_role_menus (role_id, menu_id) VALUES (1, 1);
2 INSERT INTO prefect_crm.crm_role_menus (role_id, menu_id) VALUES (1, 3);
3 INSERT INTO prefect_crm.crm_role_menus (role_id, menu_id) VALUES (2, 2);
View Code

用户表

1 INSERT INTO prefect_crm.crm_userprofile (name, user_id) VALUES ("Alex Li", 1);
2 INSERT INTO prefect_crm.crm_userprofile (name, user_id) VALUES ("Jack", 2);
View Code

用户角色关联表

1 INSERT INTO prefect_crm.crm_userprofile_roles (userprofile_id, role_id) VALUES (1, 1);
2 INSERT INTO prefect_crm.crm_userprofile_roles (userprofile_id, role_id) VALUES (2, 2);
View Code

课程表

1 INSERT INTO prefect_crm.crm_course (name, price, period, outline) VALUES ("Python", 18900, 5, "1.python语法
2 2.python基础
3 3.前端
4 4.项目");
View Code

客户表

1 INSERT INTO prefect_crm.crm_customer (name, qq, qq_name, phone, source, referral_from, content, memo, status, date, consult_course_id, consultant_id) VALUES ("大锤", "1234567890", "大锤", "1234567890", 1, "", "上课时间
2 上课地点
3 价格", "没有报名", "unregistered", "2017-10-17 01:48:53", 1, 1);
4 INSERT INTO prefect_crm.crm_customer (name, qq, qq_name, phone, source, referral_from, content, memo, status, date, consult_course_id, consultant_id) VALUES ("小锤", "1234567891", "小锤", "1234567891", 2, "", "价格
5 地点
6 学习周期", "有点低能", "unregistered", "2017-10-17 01:49:49", 1, 1);
7 INSERT 福利发放啦!沭阳的美人蕉大降价啦 连翘的价格 连翘的价格表 连翘多少钱一棵 最便宜的山樱花多少钱一棵,了解樱花价格,就到全国最大樱花产区 5公分竹子哪里最多? 秋日胭脂月季是藤本吗? 龙爪槐10月份可以种植吗? 五月份紫藤可以扦插吗? 紫藤生长在哪里? 爬藤月季苗多少钱一棵? 最大的地柏苗基地在哪,你一定不知道!

58350 94644 91572 28584 80860 72649 37267 19096 46401 82118 23455 66919 14257 13165 61683 77551 54559 72260 78396 35016 76934 55761 38157

我要说两句: (0人参与)

发布