【问题标题】:Django admin change_list: Change multiple column namesDjango admin change_list:更改多个列名
【发布时间】:2017-01-15 08:23:30
【问题描述】:

我想更改list_display 中的多个列名。您可以使用short_description 使用属性函数来执行此操作,如下所示:Django admin listview Customize Column Name。但是,如果我想更改大约 25 个列标题,这听起来不太实用。

有没有更有效的方法?

【问题讨论】:

    标签: django django-admin django-1.8


    【解决方案1】:

    第一个可行的方法是在 admin init 方法中生成这 25 个属性函数。但是现在使用映射字典和 JavaScript 中的 for-loop 实现了一种更简单的方法:

    function shorten_column_headers() {
      var headers = {
        'list_display_field_name_1': 'shortened description_1',
        'list_display_field_name_2': 'shortened description_2',
        ...
      }
      for (var field in headers) {
        var $col = $('th.column-' + field + '> div.text > a:nth-child(1)');
        $col.text(headers[field]);
      }
    }
    
    $(document).ready(function() {
      shorten_column_headers();
    });

    【讨论】:

      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 2014-07-23
      • 2017-02-10
      • 1970-01-01
      • 2013-09-02
      • 2019-10-20
      • 2011-09-10
      • 2013-04-12
      相关资源
      最近更新 更多