Django admin change_list: Change multiple column names -
i want change multiple column names in list_display
. attribute function using short_description
shown here: django admin listview customize column name. however, sounds not practical if want change around 25 column headers.
is there more efficient way?
first workable approach generate 25 attribute functions in admin init method. implemented easier approach using mapping dictionary , for
-loop in javascript:
function shorten_column_headers() { var headers = { 'list_display_field_name_1': 'shortened description_1', 'list_display_field_name_2': 'shortened description_2', ... } (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(); });
Comments
Post a Comment