else: return query.filter(self.column != "Brown") def operation(self): return 'is Brown' # Add custom filter and standard FilterEqual to ModelView class UserAdmin(sqla.ModelView): # each filter in the list is a filter operation (equals, not equals, etc) # filters with the same name will appear as operations under the same filter column_filters = [ FilterEqual(User.last_name, 'Last Name'), FilterLastNameBrown(User.last_name, 'Last Name', options=(('1', 'Yes'),('0', 'No'))) ] admin = Admin(app, template_mode="bootstrap3") admin.add_view(UserAdmin(User, db.session)) def build_sample_db(): db.drop_all() db.create_all() user_obj1 = User("Paul", "Brown", "pbrown", "*****@*****.**") user_obj2 = User("Luke", "Brown", "lbrown", "*****@*****.**") user_obj3 = User("Serge", "Koval", "skoval", "*****@*****.**") db.session.add_all([user_obj1, user_obj2, user_obj3]) db.session.commit() if __name__ == '__main__': build_sample_db() app.run(port=5000)
] # Use same rule set for edit page form_edit_rules = form_create_rules create_template = 'rule_create.jinja2' edit_template = 'rule_edit.jinja2' # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' # Create admin admin = Admin(app, 'Example: Forms', template_mode='bootstrap3') # Add views admin.add_view(FileView(File, db.session)) admin.add_view(ImageView(Image, db.session)) admin.add_view(UserView(User, db.session, name='User')) def build_sample_db(): """ Populate a small db with some example entries. """ import random import string
from flask import Flask from pyramid_admin import Admin, BaseView, expose class MyView(BaseView): @expose('/') def index(self): return self.render('index.jinja2') app = Flask(__name__) app.debug = True admin = Admin(app, name="Example: Quickstart2") admin.add_view(MyView(name='Hello')) if __name__ == '__main__': # Start app app.run()
from flask import Flask from pyramid_admin import Admin, BaseView, expose class MyView(BaseView): @expose('/') def index(self): return self.render('index.jinja2') app = Flask(__name__) app.debug = True admin = Admin(app, name="Example: Quickstart3") admin.add_view(MyView(name='Hello 1', endpoint='test1', category='Test')) admin.add_view(MyView(name='Hello 2', endpoint='test2', category='Test')) admin.add_view(MyView(name='Hello 3', endpoint='test3', category='Test')) if __name__ == '__main__': # Start app app.run()