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插件以統計圖的方式展現學生成績=-=-=-=-=-=-=-=-=-css
<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>
# -=-=-=-=-=-=判斷是不是多對多字段-=-=-=-=-
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內容=-=-=-=-=-=-=-python
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))