七.3展示、新增报名表

现在我crm项目已经做到销售可以录入客户了,且录入客户后还能给他添加跟进了!!那现在就该报名,报名完之后,缴费记录,那销售的工作就做完了!!

1.展示报名记录页面创建:

(1)urls.py中:

这里为作区分,我把url起成命名分组,customer_id是models.py中的跟进记录表的customer所咨询客户字段的外键,且我此前在views.py的展示跟进记录视图中我传了此咨询客户的id

# 展示跟进记录
url(r'consult_record_list/(?P\d+)', views.ConsultRecord.as_view(), name='consult_record'),
#展示报名记录
    url(r'enrollment_list/(?P\d+)', views.EenrollmentList.as_view(), name='enrollment'),

 

(2)views.py中:

# 展示报名记录
class EnrollmentList(View):
    def get(self, request, customer_id):
        if customer_id == '0':#能看当前销售的所有客户报名记录(Enrollment报名表中客户名称字段customer,
            # 而当前表中customer字段关联到Customer客户表,而客户表中有销售consultant字段,那就是跨表了,所以用__双下划线来查询)
            all_record = models.Enrollment.objects.filter(delete_status=False, customer__consultant=request.user)
        else:
            all_record = models.Enrollment.objects.filter(customer_id=customer_id, delete_status=False)      
        return render(request, 'crm/consultant/enrollment_list.html',
                      {
                          'all_record': all_record
                      })

(3)templates/crm/enrollment_list.html(直接复制consult_record_list.html略作修改即可)

{% extends 'layout.html' %}
{% block css %}
    
{% endblock %}

{% block content %}
    
class="panel panel-default">
class="panel-heading">Panel heading
class="panel-body"> "{% url 'add_consult_record' %}" class="btn btn-primary btn-sm">添加
"" class="form-inline pull-right"> "text" name="query" class="form-control">
"" method="post" class="form-inline"> {% csrf_token %} class="table table-condensed table-hover table-bordered"> {% for record inall_record %}{# 循环渲染 #} {# 编辑按钮#} {% endfor %}
选择 序号 客户 报名原因 期望 协议 审核 报名日期 备注 校区 所报班级 操作
"checkbox" name="id" value="{{ record.id }}"> {{ forloop.counter }} {{ record.customer }} {{ record.why_us }} {{ record.your_expectation }} {{ record.contract_agreed }} {{ record.contract_approved }} {{ record.enrolled_date }} {{ record.memo }} {{ record.school }} {{ record.enrolment_class }}
"text-align: center">
{% endblock %}

效果如下图:

七.3展示、新增报名表_第1张图片

 2.添加报名记录页面创建:

(1)urls.py中:给客户加所以要id

# 添加报名记录
url(r'enrollment/add/(?P\d+)', views.enrollment, name='add_enrollment'),

(2)views.py中:

导入form,实例化form,传到前端

 
  
from crm.forms import RegForm, CustomerForm, ConsultRecordForm,EnrollmentForm

#
添加报名记录 def enrollment(request, customer_id): form_obj = EnrollmentForm() return render(request, 'crm/enrollment.html',{'form_obj':form_obj})

(3)enrollment.html中这个是要生成form表单,所以需要form对象(复制一份customer.html并略作修改):

{% extends 'layout.html' %}
{% block content %}
    
class="panel panel-default">
class="panel-heading"> 添加报名记录
class="panel-body">
class="col-sm-8 col-sm-offset-2 ">
"" method="post" novalidate> {% csrf_token %} {% for field in form_obj %}
class="form-group row {% if field.errors %}has-error{% endif %} ">
class="col-sm-10"> {{ field }} class="help-block"> {{ field.errors.0 }}
{% endfor %}
class="form-group">
class="col-sm-offset-2 col-sm-10">
{% endblock %}

 

(4)form.py中:

# 报名表Form
class EnrollmentForm(BaseForm):
    class Meta:
        model = models.Enrollment
        exclude = ['delete_status', 'contract_approved']#不要删除状态和审批通过字段显示

 

(5)customer_list.html中:

{% extends 'layout.html' %}

{% block css %}
    
{% endblock %}

{% block content %}
    
class="panel panel-default">
class="panel-heading">Panel heading
class="panel-body"> "{% url 'add_customer' %}?{{ query_params }}" class="btn btn-primary btn-sm">添加
"" class="form-inline pull-right"> "text" name="query" class="form-control">
"" method="post" class="form-inline"> {% csrf_token %} class="table table-condensed table-hover table-bordered"> {% for customer in all_customer %} {% endfor %}
选择 序号 QQ 姓名 性别 咨询课程 班级类型 状态 最后跟进日期 销售 已报班级 跟进记录 报名记录 操作
"checkbox" name="id" value="{{ customer.id }}"> {{ forloop.counter }} {{ customer.qq }} {{ customer.name|default:'暂无' }} {{ customer.get_sex_display }} {{ customer.course }} {{ customer.get_class_type_display }} {{ customer.show_status }} {{ customer.last_consult_date }} {{ customer.consultant }} {{ customer.show_classes }} "{% url 'consult_record' customer.id %}">查看跟进 添加报名表 "{% url 'edit_customer' customer.id %}?{{ query_params }}">class="fa fa-edit fa-fw">
"text-align: center">
{% endblock %}

效果如图:点击添加后出来添加报名记录页面

七.3展示、新增报名表_第2张图片

 

 

 七.3展示、新增报名表_第3张图片

 3.给添加报名记录中做相关限制:如客户名称---限制当前的客户只能是传的id对应的客户。只能看到当前可报名的班级是当前客户的意向班级

(1)views.py中:

# 添加报名记录
def enrollment(request, customer_id):
    obj = models.Enrollment(customer_id=customer_id)#我封装给Enrollment表对象一字段并实例化传参,但是存在内容中的---拿到客户名
    form_obj = EnrollmentForm(instance=obj)#传给form
    return render(request, 'crm/enrollment.html',{'form_obj':form_obj})

(2)有了客户名称对象后可在forms.py中做限制限制customer字段的choices:

# 报名表Form
class EnrollmentForm(BaseForm):
class Meta:
model = models.Enrollment
exclude = ['delete_status', 'contract_approved']#不要删除状态和审批通过字段显示
labels = {}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# 限制当前的客户只能是传的id对应的客户
self.fields['customer'].widget.choices = [(self.instance.customer_id, self.instance.customer),]
# 限制当前可报名的班级是当前客户的意向班级---客户表里有class_list字段
self.fields['enrolment_class'].widget.choices = [(i.id, i) for i in self.instance.customer.class_list.all()]

效果如下:我点击l庆客户的添加报名表---只能看到l庆客户的客户名称

 

 

七.3展示、新增报名表_第4张图片

 

 

(3)customer_list.html中做判断公库里不应该显示某销售的客户报名记录和跟进记录可根据url网址做判断--:

 

{% extends 'layout.html' %}

{% block css %}
    
{% endblock %}

{% block content %}
    
class="panel panel-default">
class="panel-heading">Panel heading
class="panel-body"> "{% url 'add_customer' %}?{{ query_params }}" class="btn btn-primary btn-sm">添加
"" class="form-inline pull-right"> "text" name="query" class="form-control">
"" method="post" class="form-inline"> {% csrf_token %} class="table table-condensed table-hover table-bordered"> {% if request.path_info == '/crm/my_customer/' %} {% endif %} {% for customer in all_customer %} {% if request.path_info == '/crm/my_customer/' %} {% endif %} {% endfor %}
选择 序号 QQ 姓名 性别 咨询课程 班级类型 状态 最后跟进日期 销售 已报班级跟进记录 报名记录操作
"checkbox" name="id" value="{{ customer.id }}"> {{ forloop.counter }} {{ customer.qq }} {{ customer.name|default:'暂无' }} {{ customer.get_sex_display }} {{ customer.course }} {{ customer.get_class_type_display }} {{ customer.show_status }} {{ customer.last_consult_date }} {{ customer.consultant }} {{ customer.show_classes }}查看跟进 添加报名表"{% url 'edit_customer' customer.id %}?{{ query_params }}"><i class="fa fa-edit fa-fw">
"text-align: center">
{% endblock %}

效果如下图:

七.3展示、新增报名表_第5张图片

 

 七.3展示、新增报名表_第6张图片

 4.提交数据--post请求:

作判断,并从哪页点过来的跳回哪页(报名记录视图中定义获取搜索条件的方法)--效果点击添加报名表按钮并提交完后回到源页---next

(1)添加报名记录视图views.py中:

# 添加报名记录
def enrollment(request, customer_id):
    obj = models.Enrollment(customer_id=customer_id)
    form_obj = EnrollmentForm(instance=obj)
    if request.method == 'POST':
        form_obj = EnrollmentForm(request.POST,instance=obj)
        if form_obj.is_valid():
            enrollment_obj = form_obj.save()#客户的报名状态
            # 修改客户的状态
            enrollment_obj.customer.status = 'signed'
            enrollment_obj.customer.save()
            next = request.GET.get('next')#这个会获取到url网址中源页的url
            if next:
                return redirect(next)
            else:#没有next则跳到私户中
                return redirect(reverse('my_customer'))
    return render(request, 'crm/enrollment.html',{"form_obj": form_obj})

 

(2)customer_list.html中:把搜索条件添加到添加报表名a标签中

.且添加了某客户的报名记录后,他的状态显示也应该变

效果如下:

七.3展示、新增报名表_第7张图片

 

 (3)在左侧菜单栏中展示报名记录:

layout.html中:

  • 报名记录
  • 效果如图:

    七.3展示、新增报名表_第8张图片

     

     

     5.报名记录的编辑(按钮)及页面创建:

    (1)urls.py中:

        # 编辑报名记录
        url(r'enrollment/edit/(?P\d+)', views.enrollment, name='edit_enrollment'),

    (2)views.py中:

    # 展示报名记录
    class EnrollmentList(View):
        def get(self, request, customer_id):
            if customer_id == '0':#能看当前销售的所有客户报名记录(Enrollment报名表中客户名称字段customer,
                # 而当前表中customer字段关联到Customer客户表,而客户表中有销售consultant字段,那就是跨表了,所以用__双下划线来查询)
                all_record = models.Enrollment.objects.filter(delete_status=False, customer__consultant=request.user)
            else:
                all_record = models.Enrollment.objects.filter(customer_id=customer_id, delete_status=False)
            return render(request, 'crm/enrollment_list.html',
                          {
                              'all_record': all_record
                          })
    
    # 添加报名记录
    def enrollment(request, customer_id=None, edit_id=None):
        obj = models.Enrollment.objects.filter(id=edit_id).first() or models.Enrollment(customer_id=customer_id)
        form_obj = EnrollmentForm(instance=obj)
        if request.method == 'POST':
            form_obj = EnrollmentForm(request.POST,instance=obj)
            if form_obj.is_valid():
                enrollment_obj = form_obj.save()#客户的报名状态
                # 修改客户的状态
                enrollment_obj.customer.status = 'signed'
                enrollment_obj.customer.save()
                next = request.GET.get('next')#这个会获取到url网址中源页的url
                if next:
                    return redirect(next)
                else:#没有next则跳到私户中
                    return redirect(reverse('my_customer'))
        return render(request, 'crm/enrollment.html',{"form_obj": form_obj})

    (3)enrollment_list.html中加中:

    {% extends 'layout.html' %}
    {% block css %}
        
    {% endblock %}
    
    {% block content %}
        
    class="panel panel-default">
    class="panel-heading">Panel heading
    class="panel-body"> {# 添加#}
    "" class="form-inline pull-right"> "text" name="query" class="form-control">
    "" method="post" class="form-inline"> {% csrf_token %} class="table table-condensed table-hover table-bordered"> {% for record in all_record %}{# 循环渲染 #} {% endfor %}
    选择 序号 客户 报名原因 期望 协议 审核 报名日期 备注 校区 所报班级 操作
    "checkbox" name="id" value="{{ record.id }}"> {{ forloop.counter }} {{ record.customer }} {{ record.why_us }} {{ record.your_expectation }} {{ record.contract_agreed }} {{ record.contract_approved }} {{ record.enrolled_date }} {{ record.memo }} {{ record.school }} {{ record.enrolment_class }}
    "text-align: center">
    {% endblock %}

    效果如下:

    七.3展示、新增报名表_第9张图片

     

    七.3展示、新增报名表_第10张图片

     

     

    5.怎样从哪来回哪去:并从哪页点过来的跳回哪页(报名记录视图中定义获取搜索条件的方法)--效果点击编辑按钮并提交完后回到源页---next

    点击编辑完提交后/crm/enrollment_list/0把这个地址带上就行了。

    (1)views.py中:

    # 展示报名记录
    class EnrollmentList(View):
        def get(self, request, customer_id):
            if customer_id == '0':
                all_record = models.Enrollment.objects.filter(delete_status=False, customer__consultant=request.user)
            else:
                all_record = models.Enrollment.objects.filter(customer_id=customer_id, delete_status=False)
            query_params = self.get_query_params()# 调用下面的方法--获取搜索条件
            return render(request, 'crm/enrollment_list.html',
                          {
                              'all_record': all_record,
                              'query_params': query_params
                          })
        def get_query_params(self):
            # 获取添加按钮
            url = self.request.get_full_path()
            qd = QueryDict()
            qd._mutable = True
            qd['next'] = url
            query_params = qd.urlencode()
            return query_params

    (2)enrollment_list.html中:带上参数

    你可能感兴趣的:(七.3展示、新增报名表)