CRM權限管理(2)、報名流程1-銷售報名信息錄入
阿新 • • 發佈:2018-08-12
margin classlist login first mps 流程 += consul lis
流程思路
models.py
model設計思路:
具體參考:https://github.com/Fangqihan/CRM-Kingadmin/blob/master/crm/models.py
1、報名信息錄入
urls.py
from django.conf.urls import url,include
from crm import views
urlpatterns = [
url(r'^enroll/$', views.add_student, name='add_student'), # 第一步:報名信息錄入
]
views.py
@login_required def add_student(request): """銷售人員 添加 報名學生""" # 1、獲取所有咨詢用戶信息 customers = models.CustomerInfo.objects.all() # 2、獲取所有校區 branches = models.Branch.objects.all() # 3、獲取所有銷售人員 consultants = models.UserProfile.objects.filter(role__title='銷售').exclude(id=1) if request.method == 'POST': # 4、獲取提交的信息,包括 學生、選擇的班級、咨詢顧問姓名的id customerid = request.POST.get('customer') class_gradeid = request.POST.get('class_grade') consultantid = request.POST.get('consultant') from crm.models import StudentEnrollment if consultantid and class_gradeid and consultantid: # 5、數據合法則創建 StudentEnrollment 對象 student_enroll = StudentEnrollment.objects.create( customer_id=customerid, class_grade_id=class_gradeid, consultant_id=consultantid ) print('學生創建成功') # 6、生成學生完善信息 鏈接 enroll_links = 'http://127.0.0.1:8008/crm/enroll/%s/' % student_enroll.id print(enroll_links) return render(request, 'crm/student_enroll.html', locals())
創建StudentEnrollment
對象的約束:
class StudentEnrollment(models.Model):
"""學員報名"""
...
class Meta:
# 在一個班級內,customer必須是唯一的,否則會報錯
unique_together = ['customer', 'class_grade']
db_table = '學生報名'
student_enroll.html
<form class="form-horizontal" method="post"> {% csrf_token %} <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">學生</label> <div class="col-sm-10"> <!--所有可選擇的咨詢客戶--> <select name="customer" class="form-control"> <option>----------</option> {% for c in customers %} <option value="{{ c.id }}">{{ c.name }}</option> {% endfor %} </select> </div> </div> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">校區</label> <div class="col-sm-10"> <!-- 所有校區 --> <select name="branch" class="form-control" id="branch_select"> <option>----------</option> {% for b in branches %} <option value="{{ b.id }}">{{ b.name }}</option> {% endfor %} </select> </div> </div> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">班級</label> <div class="col-sm-10"> <!-- 動態顯示所有班級 --> <select name="class_grade" class="form-control" id="class_lst"> <option>----------</option> </select> </div> </div> <div class="form-group"> <label for="inputEmail3" class="col-sm-2 control-label">學習顧問</label> <div class="col-sm-10"> <!-- 顯示所有顧問 --> <select name="consultant" class="form-control"> <option>----------</option> {% for con in consultants %} <option value="{{ con.id }}">{{ con.username }}</option> {% endfor %} </select> </div> </div> <div class="form-group"> <input type="submit" class="btn btn-success" value="提交" style="float: right;margin-right: 5%"> </div> </form> <hr> <!-- --> {% if enroll_links %} <label class="control-label" style="color: green">創建成功,請將鏈接發送給學員</label> <div class=""> <input value="{{ enroll_links }}" class="form-control"> </div> {% endif %} <script> String.prototype.format= function(){ var args = arguments; return this.replace(/\{(\d+)\}/g,function(s,i){ return args[i]; }); }; // 監聽 校區input框的 change 事件 $('#branch_select').change(function () { // 1、取出選擇的校區的id var id = $(this).val(); // 2、清空班級列表 $('#class_lst [value]').remove(); $.ajax({ // 3、發送ajax請求獲取對應校區id的班級列表 url:"/crm/get_classes/"+id+"/", type:'GET', success:function (data) { var ele = ""; // 4、循環遍歷返回的班級列表信息,拼接班級option標簽 $.each(data,function (k,v) { console.log(k,v,v.id); html_str='<option value="{0}">{1}</option>'; html_str=html_str.format( v.id, v.course__name+'('+v.semester+')期' ); ele += html_str }); // 5、動態添加標簽 $('#class_lst').append(ele) } }) }) </script>
動態獲取對應校區的班級列表
1、urls.py
url(r'^get_classes/(\d+)/$', views.get_classes, name='get_classes'),
2、views.py
from crm.models import Branch, ClassList import json def get_classes(request, id): # 1、確定校區 branch = Branch.objects.filter(id=int(id)).first() # 2、獲取校區內所有班級values信息 classes = list(ClassList.objects.filter(branch=branch).values( 'id', 'branch__name', 'course__name', 'semester')) # [{'id': 1, 'branch__name': '上海', 'course__name': 'go語言', 'semester': 1},] # 3、返回班級列表的json數據 return HttpResponse(json.dumps(classes), content_type="application/json")
生成完善信息鏈接
1、前端:
{% if enroll_links %}
<label class="control-label" style="color: green">創建成功,請將鏈接發送給學員</label>
<div class="">
<input value="{{ enroll_links }}" class="form-control">
</div>
{% endif %}
2、views.py:
from crm.models import StudentEnrollment
if consultantid and class_gradeid and consultantid:
student_enroll = StudentEnrollment.objects.create(
customer_id=customerid,
class_grade_id=class_gradeid,
consultant_id=consultantid
)
print('學生創建成功')
enroll_links = 'http://127.0.0.1:8008/crm/enroll/%s/' % student_enroll.id
print(enroll_links)
CRM權限管理(2)、報名流程1-銷售報名信息錄入