django-tables2 linkColumn外部网址

时间:2012-11-03 16:51:45

标签: django django-tables2

我有2个模型属性 - model.name和model.url 我需要创建一个linkColumn,列名为= model.name并链接到指定的url model.url

有可能实现这样的目标吗?

感谢

2 个答案:

答案 0 :(得分:7)

您可以使用TemplateColumn来实现它。你的tables.py看起来应该是这样的

# yourapp/tables.py
import django_tables2 as tables
from yourapp.models import yourmodel
class YourTable(tables.Table):
    name = tables.TemplateColumn('<a href="{{record.url}}">{{record.name}}</a>')
    class Meta:
        model = yourmodel
        fields = ('name') # fields to display

您可以参考DOC了解更多信息。

答案 1 :(得分:0)

我通过创建查询数据库并呈现链接的自定义列来实现它 来自给定的属性

相关问题