标签:update mod label 列表 local djang log val head
from django.conf.urls import url,include
from crm import views
urlpatterns = [
url(r'^audit_list/$', views.audit_list, name='audit_list'),
]
from django.shortcuts import render
@login_required
def audit_list(request):
"""待审核学员列表页面"""
# 1、直接从 StudentEnrollment 筛选出所有同意合同但是没有审核通过的对象
audit_stu_list = StudentEnrollment.objects.filter(contract_agreed=1,contract_approved=0)
return render(request,'crm/audit_list.html',locals())
# 页面1
<table class="table table-bordered">
<thead>
<tr>
<td>学号</td>
<td >姓名</td>
<td >班级</td>
</tr>
</thead>
<tbody>
{% for stu in audit_stu_list %}
<tr>
<td><a href="{% url 'audit' stu.id %}">{{ stu.id }}</a></td>
<td>{{ stu.customer.name }}</td>
<td>{{ stu.class_grade }}</td>
</tr>
{% endfor %}
</tbody>
</table>
from django.conf.urls import url,include
from crm import views
urlpatterns = [
url(r'^audit_list/(\d+)/$', views.audit, name='audit')
]
class StudentEnrollForm(ModelForm):
"""信息完善form"""
class Meta:
model = StudentEnrollment
fields = '__all__'
readonly_fields = ['customer', 'consultant', 'class_grade', 'contract_agreed', 'contract_signed_time']
def __new__(cls, *args, **kwargs):
"""方法2:在实例化类对象(model_form())的时候给input框增加样式"""
for field_name, field_obj in cls.base_fields.items():
field_obj.widget.attrs.update({'class': 'form-control'})
# 设定只读字段disabled属性
if field_name in cls.Meta.readonly_fields:
field_obj.widget.attrs.update({'disabled': True})
return ModelForm.__new__(cls)
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from crm.models import StudentEnrollment
@login_required
def audit(request,id):
"""审核学员"""
student_enroll = StudentEnrollment.objects.filter(id=int(id)).first()
customer_obj = student_enroll.customer
from .forms import StudentEnrollForm
student_enroll_form = StudentEnrollForm(instance=student_enroll)
if request.method=='POST':
student_enroll_form = StudentEnrollForm(instance=student_enroll,data=request.POST)
if student_enroll.contract_approved:
return HttpResponse('该学员已经通过审核')
if student_enroll_form.data.get('contract_approved',''):
student_enroll.contract_approved=True
student_enroll.contract_approved_time=datetime.datetime.now()
# 修改咨询客户的报名状态
customer_obj.status=1
customer_obj.save()
student_enroll.save()
return redirect('/crm/audit_list/')
return render(request,'crm/audit_student_enroll.html',locals())
<form method="post">
{% csrf_token %}
{% for input_obj in student_enroll_form %}
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">{{ input_obj.label }}</label>
<div class="col-sm-10">
{{ input_obj }}
</div>
</div>
{% endfor %}
<input class="btn btn-success btn-block" type="submit" value="审核通过">
</form>
标签:update mod label 列表 local djang log val head
原文地址:https://www.cnblogs.com/fqh202/p/9464290.html