Django项目:CRM(客户关系管理系统)--07--03PerfectCRM创建基本数据02
1 from django.conf.urls import url 2 from DBadd import auth_views 3 from DBadd import crm_views 4 5 urlpatterns = [ 6 url(r'^auth_user/$', auth_views.auth_user), #Django账号表 7 8 url(r'^crm_Role/$', crm_views.crm_Role), #角色表 等基本信息 9 url(r'^crm_UserProfile/$', crm_views.crm_UserProfile),#账号表 #随机学生 10 url(r'^crm_userprofile_roles/$', crm_views.crm_userprofile_roles),#账号角色关联表 #随机学生 11 12 url(r'^crm_Customer/$', crm_views.crm_Customer), # 04客户信息表 13 14 ]
1 from django.shortcuts import render 2 from django.shortcuts import redirect 3 4 from django.contrib.auth import models 5 6 #随机字符串 7 import random 8 import string 9 10 11 12 13 #添加admin 账号 14 def auth_user(request): 15 if request.method == "GET": 16 user_list = models.User.objects.all() 17 return render(request, 'auth_user.html', {'user_list':user_list}) 18 elif request.method == "POST": 19 for i in range(50): 20 salt = ''.join(random.sample(string.ascii_letters, 6)) #随机英文 21 u=salt 22 print(u) 23 p='admin123456' 24 s='1' 25 models.User.objects.create(username=u,password=p,is_staff=s) 26 return redirect('/DBadd/auth_user/')
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <h3>添加用户</h3> 9 10 <form method="POST" action="/DBadd/auth_user/"> 11 {% csrf_token %} 12 <input type="submit"value="添加"/> 13 </form> 14 15 <h3>用户列表详细</h3> 16 <ul> 17 {% for row in user_list %} 18 <li> 19 20 <a>{{row.id}}-{{row.username}}</a> 21 22 </li> 23 {% endfor %} 24 </ul> 25 26 27 28 </body> 29 </html>
1 from django.shortcuts import render 2 from django.shortcuts import redirect 3 from django.shortcuts import HttpResponse 4 5 from crm import models 6 from django.contrib.auth import models as auth_models 7 8 # 随机字符串 9 import random 10 from random import choice 11 12 13 # 添加"""基本数据""" 14 def crm_Role(request): 15 if request.method == "GET": 16 user_list = models.Role.objects.all() 17 return render(request, 'crm_Role.html', {'user_list': user_list}) 18 elif request.method == "POST": 19 try: 20 models.Role.objects.create(name='角色学生') 21 models.Role.objects.create(name='角色销售') 22 models.Role.objects.create(name='角色老师') 23 models.Role.objects.create(name='角色校长') 24 models.Role.objects.create(name='角色系统维护') 25 26 models.Branch.objects.create(name='北京校区', addr='北京天安门') 27 models.Branch.objects.create(name='广东校区', addr='广东东莞市') 28 models.Branch.objects.create(name='上海校区', addr='上海黄浦江') 29 models.Branch.objects.create(name='福建校区', addr='福建仙游县') 30 models.Branch.objects.create(name='四川校区', addr='四川成都市') 31 32 models.Tag.objects.create(name='好,很好') 33 models.Tag.objects.create(name='很有兴趣') 34 models.Tag.objects.create(name='兴趣不大') 35 models.Tag.objects.create(name='交钱很爽快') 36 models.Tag.objects.create(name='随便问问的') 37 38 models.Course.objects.create(name='Pyton', price='6666', period='40', 39 outline='Python , 是一种面向对象的解释型计算机程序设计语言,具有丰富和强大的库,Python 已经成为继JAVA,C++之后的的第三大语言。 特点:简单易学、免费开源、高层语言、可移植性强、面向对象、可扩展性、可嵌入型、丰富的库、规范的代码等。') 40 models.Course.objects.create(name='PHP', price='8888', period='50', 41 outline='PHP语言是目前Web后端开发使用最广泛的语言,几乎绝大多数网站使用。PHP开发快速,开发成本低,周期短,后期维护费用低,开源产品丰富。') 42 models.Course.objects.create(name='Java', price='9999', period='60', 43 outline='完成本套餐的学习,学员可以全面掌握后续JavaEE开发所需的Java技术,为后续学习JavaEE开发打下坚实的基础。') 44 45 models.UserProfile.objects.create(name='ADMIN系统维护', user_id=1) 46 models.UserProfile.objects.create(name='李白销售老师', user_id=2) 47 models.UserProfile.objects.create(name='杜甫销售老师', user_id=3) 48 models.UserProfile.objects.create(name='唐伯虎销售老师', user_id=4) 49 models.UserProfile.objects.create(name='颜真卿老师', user_id=5) 50 models.UserProfile.objects.create(name='罗贯中老师', user_id=6) 51 models.UserProfile.objects.create(name='白居易老师', user_id=7) 52 models.UserProfile.objects.create(name='施耐庵老师', user_id=8) 53 models.UserProfile.objects.create(name='曹雪芹校长', user_id=9) 54 55 models.ClassList.objects.create(class_type=1, semester=2, start_date='2018-03-20', branch_id=1, course_id=1) 56 models.ClassList.objects.create(class_type=0, semester=5, start_date='2018-03-20', branch_id=1, course_id=1) 57 models.ClassList.objects.create(class_type=2, semester=8, start_date='2018-03-20', branch_id=1, course_id=1) 58 models.ClassList.objects.create(class_type=0, semester=1, start_date='2018-03-20', branch_id=1, course_id=1) 59 models.ClassList.objects.create(class_type=1, semester=3, start_date='2018-03-20', branch_id=1, course_id=1) 60 models.ClassList.objects.create(class_type=0, semester=9, start_date='2018-03-20', branch_id=1, course_id=1) 61 models.ClassList.objects.create(class_type=2, semester=6, start_date='2018-03-20', branch_id=1, course_id=1) 62 models.ClassList.objects.create(class_type=1, semester=20, start_date='2018-03-20', branch_id=1, 63 course_id=1) 64 models.ClassList.objects.create(class_type=0, semester=32, start_date='2018-03-20', branch_id=1, 65 course_id=1) 66 67 68 except: 69 return HttpResponse('基本数据已经添加了。。。') 70 71 return redirect('/DBadd/crm_Role/') 72 73 74 # 添加"""10账号表""" #随机学生 75 def crm_UserProfile(request): 76 if request.method == "GET": 77 user_list = models.UserProfile.objects.all() 78 return render(request, 'crm_UserProfile.html', {'user_list': user_list}) 79 elif request.method == "POST": 80 for i in range(50): 81 82 Rword = ''.join(''.join([chr(random.randint(0x4E00, 0x9FBF)) for i in range(3)]).split()) # 随机中文 83 n = Rword 84 85 a = models.UserProfile.objects.values("user_id").all() 86 e = auth_models.User.objects.values("id").all() 87 print('eeeee', e, type(e)) 88 x = e.difference(a) 89 # for i in x: 90 # print('zzz', x, type(x)) 91 92 l = [] 93 for i in x: 94 l.append(i['id']) 95 print('llll', l, type(l)) 96 97 if len(l) == 0: 98 return HttpResponse('请添加 admin的用户后,再来添加。。。') 99 else: 100 c = choice(l) 101 u = c 102 models.UserProfile.objects.create(name=n, user_id=u) 103 return redirect('/DBadd/crm_UserProfile/') 104 105 106 # 添加"""10账号表--11角色表""" #随机学生 107 def crm_userprofile_roles(request): 108 if request.method == "GET": 109 user_list = models.UserProfile.objects.all() 110 role_list = models.Role.objects.get(id=1) 111 return render(request, 'crm_userprofile_roles.html', {'user_list': user_list, 'role_list': role_list}) 112 elif request.method == "POST": 113 try: 114 for i in range(50): 115 b1 = models.Role.objects.get(id=1) 116 a = b1.userprofile_set.values("id").all() 117 118 e = models.UserProfile.objects.values("id").all() 119 x = e.difference(a) 120 121 l = [] 122 for i in x: 123 l.append(i['id']) 124 print('llll', l, type(l)) 125 126 if len(l) == 0: 127 return HttpResponse('请添加 数据 后,再来添加。。。') 128 else: 129 c = choice(l) 130 print('c', c, type(c)) 131 132 g1 = models.UserProfile.objects.get(id=c) 133 b1 = models.Role.objects.get(id=1) 134 g1.roles.add(b1) 135 return redirect('/DBadd/crm_userprofile_roles/') 136 except: 137 return HttpResponse('没有数据了。。。') 138 139 140 # 添加"""04客户信息表""" 141 def crm_Customer(request): 142 if request.method == "GET": 143 user_list = models.Customer.objects.all() 144 return render(request, 'crm_Customer.html', {'user_list': user_list}) 145 elif request.method == "POST": 146 for i in range(50): 147 Rword = ''.join(''.join([chr(random.randint(0x4E00, 0x9FBF)) for i in range(3)]).split()) # 随机中文 148 r=random.randint(5,18) 149 Num = "".join(random.choice("0123456789") for i in range(r)) # 随机数字 #保证qq的唯一性 150 Cnum = "".join(random.choice("123456789") for i in range(1)) # 随机数字 #不能选择0 151 try: 152 models.Customer.objects.create(name=Rword, qq=Num, qq_name=Rword, phone=Num, source=1, 153 referral_from=Rword, consult_courses_id=1, content=Rword, 154 consultant_id=Cnum, memo=Rword, date='2018-03-20') 155 except: 156 return HttpResponse('数据重复了。。。') 157 158 return redirect('/DBadd/crm_Customer/')
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <h3>添加用户</h3> 9 10 <form method="POST" action="/DBadd/crm_Role/"> 11 {% csrf_token %} 12 <input type="submit"value="添加"/> 13 </form> 14 15 <h3>用户列表详细</h3> 16 <ul> 17 {% for row in user_list %} 18 <li> 19 20 <a>{{row.id}}-{{row.name}}</a> 21 22 </li> 23 {% endfor %} 24 </ul> 25 26 27 </body> 28 </html>
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <h3>添加用户</h3> 9 10 <form method="POST" action="/DBadd/crm_UserProfile/"> 11 {% csrf_token %} 12 <input type="submit"value="添加"/> 13 </form> 14 15 16 17 18 <h3>用户列表详细</h3> 19 <ul> 20 {% for row in user_list %} 21 <li> 22 23 <a>{{row.id}}-{{row.name}}-{{row.user_id}}</a> 24 25 </li> 26 {% endfor %} 27 </ul> 28 29 30 </body> 31 </html>
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <h3>添加用户</h3> 9 10 <form method="POST" action="/DBadd/crm_userprofile_roles/"> 11 {% csrf_token %} 12 <input type="submit"value="添加"/> 13 </form> 14 15 <h3>用户列表详细</h3> 16 <ul> 17 <li> 18 <a>{{role_list.id}}-{{role_list.name}}</a> 19 </li> 20 </ul> 21 <h3>用户列表详细</h3> 22 <ul> 23 {% for row in user_list %} 24 <li> 25 <a>{{row.id}}-{{row.name}}</a> 26 </li> 27 {% endfor %} 28 </ul> 29 30 </body> 31 </html>
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <h3>添加用户</h3> 9 10 <form method="POST" action="/DBadd/crm_Customer/"> 11 {% csrf_token %} 12 <input type="submit"value="添加"/> 13 </form> 14 15 <h3>用户列表详细</h3> 16 <ul> 17 {% for row in user_list %} 18 <li> 19 20 <a>{{row.id}}-{{row.name}}</a> 21 22 </li> 23 {% endfor %} 24 </ul> 25 26 27 </body> 28 </html>
您的资助是我最大的动力!
金额随意,欢迎来赏!
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的
因为,我的写作热情也离不开您的肯定支持,感谢您的阅读,我是【颜言】!