我有一个这样定义的表,我想在其中为字段应用自定义呈现:
import django_tables2 as tables
class SetTable(tables.Table):
class Meta:
model = Set
fields = (
"series.title",
)
def render_series_title(self, value):
return 'x'
对于对象本身的简单字段(即没有句点),这是有效的。但是当存在嵌套关系时(在本例中,
Set
模型与Series
有外键关系,我想显示系列中的Title
字段),不会触发自定义渲染。我试过 render_title
、render_series_title
、render_series__title
等,但这些都没有被调用。
表格被指定为
table_class
视图中的django_filters
,并且显示数据正常,除了它使用默认渲染并绕过自定义渲染功能。
我错过了什么?