python - How to format a currency colum in Flask-Appbuilder? -
i have model price column. using modelview
, want price column right aligned 2 decimal places , currency symbol. how change format of price column?
upgrade flask-appbuilder 1.4.4 , use new @renders decorator this:
custom model properties can used on lists. usefull formating values currencies, time or dates. or custom html. simple do, first define custom property on model , use @renders decorator tell framework map class method model property:
from flask.ext.appbuilder.models.decorators import renders class mymodel(model): id = column(integer, primary_key=true) name = column(string(50), unique = true, nullable=false) custom = column(integer(20)) @renders('custom') def my_custom(self): # render columns bold on listwidget return markup('<b>' + custom + '</b>')
on view reference method column on list:
class mymodelview(modelview): datamodel = sqlainterface(mytable) list_columns = ['name', 'my_custom']
Comments
Post a Comment