Answer the question
In order to leave comments, you need to log in
Flask_table + sqlalchemy. How to change the class of a tr tag based on data from the database?
Good afternoon.
How can I change the class of the tr tag in a table generated with flask_table depending on the information I pass to the table with sqlalchemy?
I create the table like this
class Item(object):
def __init__(self, summ, describe, date, floatto):
self.summ = summ
self.describe = describe
self.date = date
self.floatto = floatto
def plus(self):
return self.floatto.lower().startswith('p')
class FloatCol(Col):
def td_format(self, content):
if content == 'plus':
return 'Приход'
elif content == 'minus':
return 'Расход'
class ItemTable(Table):
classes = ['table', 'table-hover']
summ = Col('Сумма')
describe = Col('Описание')
date = Col('Число')
floatto = Col('Тип операции')
items = Finance.query.all() # Здесь запрос к базе
table = ItemTable(items)
finance_table = table.__html__()
class ItemTable(Table):
name = Col('Name')
description = Col('Description')
def get_tr_attrs(self, item):
if item.important():
return {'class': 'important'}
else:
return {}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question