crm 添加用户 编辑用户 公户和私户的展示,公户和私户的转化

1.添加用户 和编辑可以写在一起

urls.py

    url(r‘^customer_add/‘, customer.customer_change, name=‘customer_add‘),
    url(r‘^customer_edit/(\d+)/‘, customer.customer_change, name=‘customer_edit‘),

form.py

class BSForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)# 这2句相当于执行了父类的init方法
        # 自定义操作
        for fied in self.fields.values():
            fied.widget.attrs.update({‘class‘: ‘form-control‘})
# 客户的form
class CustomerForm(BSForm):
    class Meta:
        model = models.Customer#找到这个表
        fields = ‘__all__‘## 所有字段

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)#去掉course的form-control样式
        self.fields[‘course‘].widget.attrs.pop(‘class‘)

views目录下  函数添加

def customer_change(request, edit_id=None):
    obj = models.Customer.objects.filter(pk=edit_id).first()
    # 处理POST
    if request.method == ‘POST‘:
        # 包含提交的数据 原始数据
        form_obj = CustomerForm(request.POST, instance=obj)
        if form_obj.is_valid():#文件校验
            form_obj.save()
            # 跳转到展示页面
            return redirect(reverse(‘customer_list‘))
    else:
        form_obj = CustomerForm(instance=obj)#也就是空的值

    title = ‘编辑客户‘ if edit_id else ‘添加客户‘

    return render(request, ‘customer_change.html‘, {‘title‘: title, ‘form_obj‘: form_obj})
customer_change.html
{% extends ‘layout.html‘ %}
{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">
            <h4 class="panel-title">添加客户</h4>
        </div>
        <div class="panel-body">
            <div class="col-lg-8 col-lg-offset-2 " style="margin-top: 10px">
                <form class="form-horizontal" novalidate method="post">
                    {% csrf_token %}

                    {% for field in form_obj %}
                        <div class="form-group {% if field.errors %}has-error{% endif %}">
                  //选中报红的样式

                            <label for="{{ field.id_for_label }}"//字段名字
                                   class="col-sm-2 control-label">{{ field.label }}</label>
                            <div class="col-sm-10">
                                {{ field }}

                                <span class="help-block"> {{ field.errors.0 }}</span>
                            </div>
                        </div>
                    {% endfor %}
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-default">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
{% endblock %}

2. 公户和私户的展示

    # 展示公户
    # url(r‘^customer_list/‘,customer.customer_list,name=‘customer_list‘),
    url(r‘^customer_list/‘,customer.CustomerList.as_view(),name=‘customer_list‘),

    # 展示私户
    # url(r‘^my_customer/‘,customer.customer_list,name=‘my_customer‘),
    url(r‘^my_customer/‘,customer.CustomerList.as_view(),name=‘my_customer‘),

之前的函数

def customer_list(request):#公户私户显示
    if request.path_info == reverse(‘customer_list‘):
        all_customer = models.Customer.objects.filter(consultant__isnull=True)
    else:
        all_customer = models.Customer.objects.filter(consultant=request.user_obj)
    return render(request, ‘customer_list.html‘, {‘all_customer‘: all_customer})

views/customer.py

# 展示客户列表 CBV
from django.views import View
class CustomerList(View):
    def get(self, request, *args, **kwargs):
        if request.path_info == reverse(‘customer_list‘):

            all_customer = models.Customer.objects.filter(consultant__isnull=True)
        else:
            all_customer = models.Customer.objects.filter(consultant=request.user_obj)

        page = Pagination(request.GET.get(‘page‘, 1), all_customer.count(), )

        return render(request, ‘customer_list.html‘, {
            ‘all_customer‘: all_customer[page.start:page.end],
            ‘page_html‘: page.page_html
        })

    def post(self, request, *args, **kwargs):
        action = request.POST.get(‘action‘)  # multi_apply  multi_pub
        # 判断是否有相应的操作 反射
        if hasattr(self, action):
            # 有 获取并且执行
            func = getattr(self, action)
            print(func)
            func()
        else:
            return HttpResponse(‘非法操作‘)
        return self.get(request, *args, **kwargs)

    def multi_apply(self, ):
        ids = self.request.POST.getlist(‘ids‘)
        # 把提交的客户的ID 都变成当前用户的私户
        # 方式一  查询的客户
        # models.Customer.objects.filter(pk__in=ids).update(consultant=self.request.user_obj)
        # models.Customer.objects.filter(pk__in=ids).update(consultant_id=self.request.session.get(‘pk‘))
        # 方式二 查用户
        self.request.user_obj.customers.add(*models.Customer.objects.filter(pk__in=ids))
    def multi_pub(self):
        ids = self.request.POST.getlist(‘ids‘)
        # 把提交的客户的ID
        # 方式一  查询的客户
        models.Customer.objects.filter(pk__in=ids).update(consultant=None)
        # 方式二 查用户
        # self.request.user_obj.customers.remove(*models.Customer.objects.filter(pk__in=ids))

customer_list.html

{% extends ‘layout.html‘ %}

{% block content %}

    <a class="btn btn-success btn-sm" style="margin: 3px" href="{% url ‘customer_add‘ %}"> <i
            class="fa fa-plus-square"></i> 添加 </a>

    <form action="" method="post" class="form-inline">
        {% csrf_token %}
        <select name="action" id="" class="form-control">

            {% if request.path_info == ‘/crm/my_customer/‘ %}
                <option value="multi_pub"> 私户变公户</option>
            {% else %}
                <option value="multi_apply"> 公户变私户</option>
            {% endif %}

            <option value="multi_del"> 批量删除</option>

        </select>
        <button class="btn btn-sm btn-primary">提交</button>
        <table class="table table-bordered table-hover">

            <thead>
            <tr>
                <th>选择</th>
                <th>序号</th>
                <th>QQ</th>
                <th>姓名</th>
                <th>性别</th>
                {#        <th>出生日期</th>#}
                {#        <th>电话</th>#}
                <th>客户来源</th>
                <th>咨询课程</th>
                <th>状态</th>
                <th>最后跟进</th>
                <th>销售</th>
                <th>已报班级</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            {% for customer in all_customer %}

                <tr>
                    <td>
                        <input type="checkbox" name="ids" value="{{ customer.pk }}">
                    </td>
                    <td>{{ forloop.counter }}</td>
                    <td>{{ customer.qq }}</td>
                    <td>{{ customer.name|default:‘未填写‘ }}</td>
                    <td>{{ customer.get_sex_display }}</td>
                    {#            <td>{{ customer.birthday|default:‘未填写‘ }}</td>#}
                    {#            <td>{{ customer.phone }}</td>#}
                    <td>{{ customer.get_source_display }}</td>
                    <td>{{ customer.course }}</td>
                    <td>
                        {{ customer.show_status }}
                    </td>
                    <td>{{ customer.last_consult_date }}</td>
                    <td>{{ customer.consultant }}</td>
                    {#            <td>{{ customer.class_list.all }}</td>#}
                    <td>{{ customer.show_class }}</td>
                    <td>

                        <a href="{% url ‘customer_edit‘ customer.pk %}"> <i class="fa fa-pencil-square-o"></i> </a>
                    </td>
                </tr>

            {% endfor %}

            </tbody>
        </table>
    </form>

{% endblock %}
 

原文地址:https://www.cnblogs.com/zaizai1573/p/10540308.html

时间: 2024-08-28 20:54:37

crm 添加用户 编辑用户 公户和私户的展示,公户和私户的转化的相关文章

[App Store Connect帮助]二、 添加、编辑和删除用户(3)添加和编辑用户

您可以在“用户和访问”中添加和编辑用户. 如果您以个人名义在“Apple 开发者计划”注册,您可以授权用户访问您 App Store Connect 中的内容.所有用户只拥有 App Store Connect 的访问权限,且不属于您的“Apple 开发者计划”团队.他们将不会获得 Apple Developer 网站的会员资源或其他会员权益的访问权限. 如果您以组织名义在“Apple 开发者计划”注册,您可以向您的团队添加成员.所有用户都属于您组织的“Apple 开发者计划”团队.他们将获得

数据库实例: STOREBOOK &gt; 用户 &gt; 编辑 用户: PUBLIC

ylbtech-Oracle:数据库实例: STOREBOOK  >  用户  >  编辑 用户: PUBLIC 编辑 用户: PUBLIC 1. 一般信息返回顶部 1.1, 1.2, 2. 角色返回顶部 2.1, 2.2, 3. 系统权限返回顶部 3.1, 3.2, 4. 对象权限返回顶部 4.1, 4.2, 5. 限额返回顶部 5.1, 作者:ylbtech出处:http://ylbtech.cnblogs.com/本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在

数据库实例: STOREBOOK &gt; 用户 &gt; 编辑 用户: DBSNMP

ylbtech-Oracle:数据库实例: STOREBOOK  >  用户  >  编辑 用户: DBSNMP 编辑 用户: DBSNMP 1. 一般信息返回顶部 1.1, 1.2, 2. 角色返回顶部 2.1, 2.2, 3. 系统权限返回顶部 3.1, 3.2, 4. 对象权限返回顶部 4.1, 4.2, 5. 限额返回顶部 5.1, 5.2, 6. 使用者组切换权限返回顶部 6.1, 6.2, 7. 代理用户返回顶部 7.1, 7.2, 8.返回顶部 8.1, 作者:ylbtech出处

域用户和组帐户的管理之一次同时添加多个用户帐户篇

如果利用AD图形界面来创建大量用户帐户的话,将浪费很多时间用于重复操作相同的步骤.此时可以利用系统内置的工作csvde.exe.ldifde.exe.dsadd.exe等程序来节省创建用户帐户的时间. csvde.exe: 可以利用它来添加用户帐户(或其他类型的对象),但是不能利用它来修改或删除用户帐户.您需要事先利用文本编辑器将用户帐户数据创建到纯文本文件内,然后利用csvde.exe将文件内的这些用户帐户一次性导入到AD数据库中. ldifde.exe: 可以利用它来添加.删除.修改用户帐户

[App Store Connect帮助]二、 添加、编辑和删除用户(2)查看并编辑您的个人帐户

您可以在 App Store Connect 的“编辑个人资料”中查看和编辑个人信息.如果您的 Apple ID 与多个帐户相关联,您可以在您的用户帐户之间切换. 查看您的个人帐户 在任意 App Store Connect 页面的右上角点按您的用户名,然后选择“编辑个人资料”. 设置您的首选货币 您选择的首选货币是您为您的 App 或 App 内购买项目选择定价时在 App Store Connect 中显示的默认货币.并非在 App Store 中显示给顾客的货币,或者支付给您的货币. 在任

用户编辑新建_AngularJS实现

实现思路:分步骤完成开发,逐渐添加功能:1.实现输出users对象.2.实现点击“编辑”按钮,在表单中显示firstname和lastname,并不可修改.3.实现“新建用户”和“编辑用户”的切换.4.实现“创建新用户”按钮. 1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>无标题文档</title> 6 <scrip

centos添加和删除用户及 xxx is not in the sudoers file.This incident will be reported.的解决方法

1.添加用户,首先用adduser命令添加一个普通用户,命令如下: #adduser tommy //添加一个名为tommy的用户 #passwd tommy   //修改密码 Changing password for user tommy. New UNIX password:     //在这里输入新密码 Retype new UNIX password:  //再次输入新密码 passwd: all authentication tokens updated successfully.

Shell 脚本添加或删除用户及命令使用方法

Shell 要求:写一个脚本 一.添加10个用户user1到user10,密码同用户名,,若用户存在,但要求只有用户不存在的情况下才能添加,格式为/useradd.sh 解答思路:1.使用for 循环语句添加用户 user1 到user 10 2.判断用户是否存在,若存在,则echo 用户已存在 ,若不存在,添加用户 ,并设置密码与用户名相同 . 脚本: vim useradd.sh  并赋予+x权限. #!/bin/bash # for I in{1..10};do      if id us

加链接太麻烦?使用 linkit 模块提升用户编辑体验

在制作网站内容时,适当地添加链接会非常用利于网站内容的SEO.加入链接的文章可以让访客了解到更多相关内容,从而提升文章的质量.被链接到的内容也能因此获得更多的访问和关注.只不过,在内容编辑时添加链接却是一件麻烦且费力的事情. 在 Drupal 中,可以用 Linkit 模块来提升添加链接的编辑体验.Linkit会在可视化编辑器中新增一个添加链接的按钮控件,用户可以在弹出的对话框中快速地搜索本地内容并添加链接.对话框中提供自动完成字段,一旦找到想要的内容,点击“添加链接”就完成了.相对于在网站中进