@staticmethod
def _get_action_description(func, name):
return getattr(func, 'short_description', capfirst(name.replace('_', ' ')))
def _get_base_actions(self):
"""Return the list of actions, prior to any request-based filtering."""
actions = []
base_actions = (self.get_action(action) for action in self.actions or [])
# get_action might have returned None, so filter any of those out.
base_actions = [action for action in base_actions if action]
base_action_names = {name for _, name, _ in base_actions}
# Gather actions from the admin site first
for (name, func) in self.admin_site.actions:
if name in base_action_names:
continue
# RIGHT HERE IS WHERE IT CREATES THE TEXT FOR THE COLUMN TITLE/TH ELEMENT
description = self._get_action_description(func, name)
actions.append((func, name, description))
# Add actions from this ModelAdmin.
actions.extend(base_actions)
return actions
1条答案
按热度按时间vsmadaxz1#
你完全可以将HTML嵌入到title/
th
中用于admin列。不要使用admin.display decorator
,可以这样尝试:你可以在源代码中看到它是如何工作的:https://github.com/django/django/blob/3.2.16/django/contrib/admin/options.py#L860