如何在flask-admin中为过滤器设置动态标签

时间:2018-01-11 08:08:10

标签: python-2.7 flask flask-admin

我有一个要求,我需要允许我的网站管理员为我的列表页面设置我的列的标签。我使用以下代码从表单数据库中获取标签并将其设置为列。

def get_field():
    db=getConnection()
    field_cur = db.cursor()
    getField = "select column_name, name, validation from slb_opp_fields"
    field_cur.execute(getField)
    ValField = {}
    for k in field_cur.fetchall():
        if k[2] == 'Y':
            ValField[k[0]] = k[1]
        else:
            ValField[k[0]] = k[1]
    return ValField


@property
def column_labels(self):
    ValueField, ValField =get_field()
    column_lables = {
        'etb_id': ValField['etb_id'],
        'network_id': ValField['network_id'],
        'domain_area': ValField['domain_area'],
        'service_offering': ValField['service_offering'],
        'customer_unit': 'Customer Unit'
    }

@property
def column_filters(self):
    ValueField, ValField =get_field()
    column_lables = {
        'etb_id': ValField['etb_id'],
        'network_id': ValField['network_id'],
        'domain_area': ValField['domain_area'],
        'service_offering': ValField['service_offering'],
        'customer_unit': 'Customer Unit'
    }

@property
def _list_columns(self):
    return self.get_list_columns()

@_list_columns.setter
def _list_columns(self, value):
    pass

@property
def _filters(self):
    return self.get_filters()

@_filters.setter
def _filters(self, value):
    pass

Where get_field() function fetches data for label(name) from database table as follows:

def get_field():
    db=getConnection()
    field_cur = db.cursor()
    getField = "select column_name, name, validation from slb_opp_fields"
    field_cur.execute(getField)
    ValField = {}
    for k in field_cur.fetchall():
        if k[2] == 'Y':
            ValField[k[0]] = k[1]
        else:
            ValField[k[0]] = k[1]
    return ValField

此代码适用于动态表格列中的标签,但过滤器不会动态反映标签名称更改。

我根据“flask-admin / flask_admin / model / base.py”使用了setter,但它仍然没有反映Add Filter部分标签的更改。

Python版本2.7.6 烧瓶版本:0.10

0 个答案:

没有答案