Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7405933
  • 博文数量: 1756
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16232
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1756)

文章存档

2024年(2)

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: Python/Ruby

2023-02-16 14:53:27

xadmin没有changelist_view,可以用object_list_template指定模板

点击(此处)折叠或打开

  1. class CostAdmin(object):
  2.     list_display = ("id", "idcname", "costnum", "content", "createdate")
  3.     list_per_page = 10
  4.     object_list_template = 'change_list.html' #自义模板


  5.         #自定义模板 接参过滤数据
  6.     def get_list_queryset(self):
  7.         this_year = self.request.GET.get("year")
  8.         if not this_year:
  9.             queryset = super(CostAdmin, self).get_list_queryset()
  10.             return queryset
  11.         else:
  12.             queryset = super(CostAdmin, self).get_list_queryset()
  13.             return queryset.filter(createdate__year=this_year)
  14.     
  15.     #添加数据 https://www.cnblogs.com/roystime/p/6875709.html
  16.     def get_context(self):
  17.         #读取所需要的数据
  18.         #context = CommAdminView.get_context(self)
  19.         context = super().get_context()
  20.         this_year = self.request.GET.get("year")
  21.         if not this_year:
  22.             this_year = time.strftime("%Y", time.localtime(time.time()))
  23.         year_data = (
  24.             models.Cost.objects.filter(createdate__year=this_year).extra(select={"year":"date_format(createdate,'%%Y')"}).values("year","idcname").annotate(sum_costnum=Sum("costnum")).values("year","idcname__name","sum_costnum").order_by()
  25.         )
  26.         。。。。。
  27.         。。。。。

  28.         context.update({"this_year":this_year})
  29.         context.update({"link_res":link_res})
  30.         context.update({"year_data":year_data})
  31.         context.update({"month_data":month_data})
  32.         context.update({"legend":list(dict1.keys())})
  33.         context.update({"axis":axis})
  34.         context.update({"result":result})

  35.         return context

  36. xadmin.site.register(models.Cost, CostAdmin)

模板可以引入templates/change_list.html 

点击(此处)折叠或打开

  1. {% extends "xadmin/views/model_list.html" %}
  2. {% load static %}

  3. {% block extrahead %}
  4. <script type="text/javascript" src="/static/echarts/5.3.3/echarts.min.js"></script>

  5. {% endblock %}

  6. {% block content %}

  7. <h4>{{this_year}}年度汇总</h4>
  8. <table class="table table-bordered table-striped table-hover">
  9.   <thead>
  10.     <tr>
  11.     <th>年度</th>
  12.     <th>供应商</th>
  13.     <th>金额</th>
  14.   </tr>
  15.   </thead>
  16.   <tbody>
  17.   {% for i in year_data %}
  18.   <tr>
  19.     <td>{{i.year}}</td>
  20.     <td>{{i.idcname__name}}</td>
  21.     <td>{{i.sum_costnum}}</td>
  22.   </tr>
  23.   {% endfor %}
  24.   </tbody>
  25. </table>
  26. <hr>
  27. {% if link_res %}
  28. {% for i in link_res %}
  29. <a href="?year={{i.0}}"><font size="5">{{i.1}}</font></a>
  30. {% endfor %}
  31. {% endif %}
  32. <hr>

  33. {{ block.super }}
  34. <hr>
  35.     <div id="main" style="width:100%;height:450px;"></div>
  36.     <script type="text/javascript">
  37.         // 基于准备好的dom,初始化echarts实例
  38.         var myChart = echarts.init(document.getElementById('main'));
  39.  
  40.         // 指定图表的配置项和数据
  41.         var option = {
  42.             title: {
  43.                 text: '每月统计'
  44.             },
  45.             tooltip: {},
  46.             label: {
  47.                 show: false,
  48.             },
  49.             legend: {
  50.                 data:{{ legend|safe }},
  51.                 right: '4%',
  52.             },
  53.             xAxis: {
  54.                 data: {{ axis|safe }}
  55.             },
  56.             yAxis: {
  57.                 type: 'log',
  58.                 min:1,
  59.                 logBase:10
  60.             },
  61.             series: {{ result|safe }}
  62.         };
  63.  
  64.         // 使用刚指定的配置项和数据显示图表。
  65.         myChart.setOption(option);

  66.     </script>


  67. {% endblock %}

阅读(273) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~