Created
September 10, 2014 18:58
-
-
Save pawl/5fcd1d206c874d091302 to your computer and use it in GitHub Desktop.
Override get_query based on GET parameter - Flask-Admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from application import db | |
from application.views.modelview import ModelView | |
from application.models import Things # has an attribute called thing_type | |
class MyModelView(ModelView): | |
def get_query(self): | |
thing_type = request.args.get('type', None) # pretending we have a GET parameter called "type" | |
if thing_type == "type1": | |
return super(ModelView, self).get_query().filter(Things.thing_type.like('type1 %')) | |
elif thing_type == "type2": | |
return super(ModelView, self).get_query().filter(Things.thing_type.like('type2 %')) | |
else: | |
return super(ModelView, self).get_query() | |
# note, you can't define get_query inside of def index_view(self) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment