Spaces:
Runtime error
Runtime error
Commit
·
d52fe98
1
Parent(s):
acddfb1
Create tables.py
Browse files- scraper/tables.py +19 -0
scraper/tables.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import django_tables2 as tables
|
| 2 |
+
from .models import Product
|
| 3 |
+
from django.utils.safestring import mark_safe
|
| 4 |
+
|
| 5 |
+
class ProductTable(tables.Table):
|
| 6 |
+
url = tables.Column(verbose_name='URL')
|
| 7 |
+
|
| 8 |
+
def render_url(self, value, record):
|
| 9 |
+
if value:
|
| 10 |
+
link = f'<a href="{value}" target="_blank">{value}</a>'
|
| 11 |
+
return mark_safe(link)
|
| 12 |
+
else:
|
| 13 |
+
return ''
|
| 14 |
+
class Meta:
|
| 15 |
+
model = Product
|
| 16 |
+
template_name = "django_tables2/bootstrap.html"
|
| 17 |
+
fields = ("id","product_id","title", "ingredients", "url", "store_name")
|
| 18 |
+
attrs = {"class": "table table-striped table-bordered table-hover"}
|
| 19 |
+
order_by = ('id',)
|