django-tables2 linkColumn external url

后端 未结 2 372
谎友^
谎友^ 2021-01-13 17:02

I have 2 model attributes - model.name and model.url I need to create a linkColumn that column name = model.name and link to the url specified in model.url

Is it po

2条回答
  •  野的像风
    2021-01-13 17:20

    You can use TemplateColumn to achieve it. Your tables.py should look something like this

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

    You may refer to the DOC, for more info.

提交回复
热议问题