Python Django表2-获取列内容
我试着做一些类似的事情:Python Django表2-获取列内容,python,django,django-tables2,Python,Django,Django Tables2,我试着做一些类似的事情: if filed_1: field_1 = tables.LinkColumn('fields:detail', args=[A('field_1')]) else: field_2 = tables.LinkColumn('fields:detail', args=[A('field_2')]) 如果表包含字段_1中的数据,则字段_1必须是链接列,否则字段_2是链接列 提前感谢。您可以使用: titol=tables.TemplateColumn( 模板\u
if filed_1:
field_1 = tables.LinkColumn('fields:detail', args=[A('field_1')])
else:
field_2 = tables.LinkColumn('fields:detail', args=[A('field_2')])
如果表包含字段_1中的数据,则字段_1必须是链接列,否则字段_2是链接列
提前感谢。您可以使用:
titol=tables.TemplateColumn(
模板\u代码=u”“”
{%if record.field_1%}
{%else%}
{%endif%}
""" ,
详细名称=u“字段”,
排序依据=('field_1'、'field_2')
)
titol = tables.TemplateColumn(
template_code = u"""
{% if record.filed_1 %}
<a href={% url 'fields:detail' record.field_1.pk %}>
{{record.field_1}}</a>
{% else %}
<a href={% url 'fields:detail' record.field_2.pk %}>
{{record.field_2}}</a>
{% endif %}
""" ,
verbose_name= u"field",
order_by=( 'field_1', 'field_2' )
)