crm 简约笔记

crm
# 给modelform使用的
    tutor = models.ForeignKey(verbose_name='班主任', to='UserInfo', related_name='classes',limit_choices_to={"depart__in":[1004,1005]},on_delete=models.CASCADE)
    # limit_choices_to={"depart__in":[1004,1005]}
        modelform做渲染时,使用筛选后的数据。
        

# 显示choices的值
    record_choices = (('checked', "已签到"),)
    record = models.CharField("上课纪录", choices=record_choices, default="checked", max_length=64)

    def show_gender(self,obj=None,is_header=False):
        if is_header:
            return '性别'
        return obj.get_gender_display()
        
        
# CSS3 ::selection 选择器    
# 使被选中的文本成为红色:        
::selection
{
color:#ff0000;
}


# 获取完整url,包括?后的请求信息
request.get_full_path_info()
# 更新update操作,当filter(xx=oo)的xx不确定时,可用字典传参解决。
d = {}
key_id = request.POST.get('name')
val = request.POST.get('val')
key,id = key_id.split('_')
d[key]=val
o = StudyRecord.objects.filter(pk=id).update(**d)





#-==============highcharts插件以统计图的方式展示学生成绩=-=-=-=-=-=-=-=-=-

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.css">
<script src="/static/js/jquery-1.12.4.min.js"></script>
<script src="/static/chart/highcharts.js"></script>
<style>
    span {
        padding: 2px 5px;
        margin: 2px;
        border: 1px solid deepskyblue;
    }
</style>

<div id="container" style="width:600px;height:400px" class="col-md-offset-1"></div>
<script>
    $(".check_chart").click(function () {

        $.ajax({
            url: "",
            type: "get",
            data: {
                sid: $(this).attr("sid"),
                cid: $(this).attr("cid")
            },
            success: function (data) {

                // 显示柱状图
                var chart = Highcharts.chart('container', {
                    chart: {
                        type: 'column'
                    },
                    title: {
                        text: '查看成绩'
                    },
                    subtitle: {
                        {#text: '数据截止 2017-03,来源: <a href="https://en.wikipedia.org/wiki/List_of_cities_proper_by_population">Wikipedia</a>'#}
                    },
                    xAxis: {
                        type: 'category',
                        labels: {
                            rotation: -45  // 设置轴标签旋转角度
                        }
                    },
                    yAxis: {
                        min: 0,
                        title: {
                            text: '分数'
                        }
                    },
                    legend: {
                        enabled: false
                    },
                    tooltip: {
                        pointFormat: '分数: <b>{point.y:.2f}</b>'
                    },
                    series: [{
                        name: '总人口',
                        data: data,
                        dataLabels: {
                            enabled: true,
                            rotation: -40,
                            color: '#fff29f',
                            align: 'right',
                            format: '{point.y:.1f}', // :.1f 为保留 1 位小数
                            y: 10
                        }
                    }]
                });
            }
        })
    })
</script>
View Code

 



# -=-=-=-=-=-=判断是否是多对多字段-=-=-=-=-
    filter_field_obj = self.config.model._meta.get_field(filter_field)  # 字段对象
    # print(type(filter_field_obj))
    if isinstance(filter_field_obj,ManyToManyField) or isinstance(filter_field_obj,ForeignKey):
        data_list = filter_field_obj.remote_field.model.objects.all()       # 获取外键表数据

        
# =-=-=-=-=-=-=-根据model不同字段渲染table内容=-=-=-=-=-=-=-

    if isinstance(field_obj,ManyToManyField):
        to_objlist = getattr(obj,field).all()
        t=[]
        for to_obj in to_objlist:
           t.append('<span class="author pull-left">%s</span>'%str(to_obj))
        val = mark_safe(''.join(t))
    else:
        if field_obj.choices:
            val = getattr(obj, 'get_'+field+'_display')
        else:
            val = getattr(obj,field)
        # 检测是否指定编辑跳转字段
        if field in self.config.list_display_links:
            val = mark_safe('<a href="%s%s">%s</a>'%(self.config.get_change_url(obj),par,val))

 

posted @ 2018-11-28 18:31  ming-yuan  阅读(193)  评论(0编辑  收藏  举报