I define a specific Flask Table as follows
class MyTable(Table):
def __init__(self, table_id, rows):
self.table_id = table_id
super().__init__(rows)
Code = Col('Code', column_html_attrs = {'class': 'apply-filter'})
Now, if I try to generalize it by moving the Code
attribute inside the __init__
,
def __init__(self, table_id, rows, key):
self.table_id = table_id
self.__dict__[key] = Col(key, column_html_attrs = {'class': 'apply-filter'})
super().__init__(rows)
something goes wrong and it is no longer shown.
I've also tried with self.Code = ...
(that is not what I want because it is not generalized) but it also fails.
Conceptual question
Even if I've found a working answer, I'm still not fully satisfied with it. Why wasn't my original code good as well? Doesn't the constructor of the parent class see the fields (dynamically) created in the initialization of the derived class?