Exemplo n.º 1
0
def add_customer(requsest):
    form_obj = Customer_form()
    if requsest.method == 'POST':
        form_obj = Customer_form(requsest.POST)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('customer_list'))
        print(form_obj.errors)
    return render(requsest, 'consultant/add_customer.html',
                  {'form_obj': form_obj})
Exemplo n.º 2
0
def edit_customer(request, pk):
    obj = models.Customer.objects.filter(pk=pk).first()
    form_obj = Customer_form(
        instance=obj)  # 实例  对象 拿到对应对象的原始数据,此时form_obj包含了原始数据
    if request.method == 'POST':
        form_obj = Customer_form(data=request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            return redirect(reverse('own_customer'))
    return render(request, 'customer_form.html', {'form_obj': form_obj})
Exemplo n.º 3
0
def customer_change(request, pk=None):
    start_obj = models.Customer.objects.filter(pk=pk).first()
    form_obj = Customer_form(instance=start_obj)
    if request.method == 'POST':
        form_obj = Customer_form(data=request.POST, instance=start_obj)
        if form_obj.is_valid():
            form_obj.save()
            next = request.GET.get('next')
            if next:
                return redirect(next)
            return redirect(reverse('customer'))
    title = '编辑客户' if pk else '新建用户'
    return render(request, 'customer_change.html', {'form_obj': form_obj, 'title': title})
Exemplo n.º 4
0
def customer_change(request, pk=None):
    obj = models.Customer.objects.filter(pk=pk).first()
    consult_mes = models.ConsultRecord.objects.filter(pk=pk)
    print(consult_mes)
    form_obj = Customer_form(
        instance=obj)  # 实例  对象 拿到对应对象的原始数据,此时form_obj包含了原始数据
    if request.method == 'POST':
        form_obj = Customer_form(data=request.POST, instance=obj)
        if form_obj.is_valid():
            form_obj.save()
            next = request.GET.get('next')
            if next:
                return redirect(next)
            return redirect(reverse('own_customer'))
    title = '编辑客户' if pk else '添加客户'
    return render(request, 'form.html', {'form_obj': form_obj, 'title': title})