File size: 663 Bytes
d52fe98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import django_tables2 as tables
from .models import Product
from django.utils.safestring import mark_safe

class ProductTable(tables.Table):
    url = tables.Column(verbose_name='URL')

    def render_url(self, value, record):
        if value:
            link = f'<a href="{value}" target="_blank">{value}</a>'
            return mark_safe(link)
        else:
            return ''
    class Meta:
        model = Product
        template_name = "django_tables2/bootstrap.html"
        fields = ("id","product_id","title", "ingredients", "url", "store_name")
        attrs = {"class": "table table-striped table-bordered table-hover"}
        order_by = ('id',)