We do this in our application, overriding ModelView.
https://github.com/mrjoes/flask-admin/blob/master/flask_admin/contrib/sqla/view.py#L654
I was looking a bit for the source code for Flask-Admin, and they have simplified the use of the API since we last edited this code because it looks like you can just do:
from flask.ext.admin.contrib.sqla.view import ModelView, func class PaidOrderView(ModelVew): def get_query(self): return self.session.query(self.model).filter(self.model.paid==True) def get_count_query(self): return self.session.query(func.count('*')).filter(self.model.paid==True)
(We redefined get_list (), which is not so big.)
Then you can use it, for example:
admin.add_view(PaidOrderView(Order, db.session))
Let me know if this does not work for you, and I can take a look again.
source share