Search code examples
pythonflaskflask-admin

Whitelist columns in flask-admin View


I have a sqlalchemy model with 20+ columns with a lot of data that should not be shown in flask-admin lists. (ex: Long markdown data)

I'm currently using a blacklist way (column_exclude_list) to exclude most of the columns, but the code is messy and I suspect it will be a liability since I have to modify the code every time I modify the model (and it's going to be modified a lot).

from flask.ext.admin.contrib.sqla.view import ModelView


class CompanyView(ModelView):
    column_exclude_list = ['account_bank_code', 'account_name', 'account_number', 'address1', 'address2', ... ( long list of column names )]

Is there a whitelist way of setting what columns to expose in flask-admin's BaseView?


Solution

  • Nevermind, I found it. I just have to set column_list instead of column_exclude_list.

    https://flask-admin.readthedocs.org/en/latest/api/mod_model/#flask_admin.model.BaseModelView.column_list