我无法发表评论,所以我需要添加另一个答案。我将更正“render”调用在参数列表中不应包含“self”。
class CustomTextLinkColumn(LinkColumn):
def __init__(self, viewname, urlconf=None, args=None,
kwargs=None, current_app=None, attrs=None, custom_text=None, **extra):
super(CustomTextLinkColumn, self).__init__(viewname, urlconf=urlconf,
args=args, kwargs=kwargs, current_app=current_app, attrs=attrs, **extra)
self.custom_text = custom_text
def render(self, value, record, bound_column):
return super(CustomTextLinkColumn, self).render(
self.custom_text if self.custom_text else value,
record, bound_column)
使用,正如 Serafeim 所说:
id = CustomTextLinkColumn('downloadFile', args=[A('pk')],
custom_text='Export', verbose_name='Export', )