本文整理匯總了Python中flask_admin.contrib.sqla.ModelView方法的典型用法代碼示例。如果您正苦於以下問題:Python sqla.ModelView方法的具體用法?Python sqla.ModelView怎麽用?Python sqla.ModelView使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask_admin.contrib.sqla
的用法示例。
在下文中一共展示了sqla.ModelView方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: register_admin
# 需要導入模塊: from flask_admin.contrib import sqla [as 別名]
# 或者: from flask_admin.contrib.sqla import ModelView [as 別名]
def register_admin(self, admin):
admin.add_view(ModelView(self.DatabaseUserRecord, self.session))
示例2: start_api
# 需要導入模塊: from flask_admin.contrib import sqla [as 別名]
# 或者: from flask_admin.contrib.sqla import ModelView [as 別名]
def start_api(swagger_host="0.0.0.0", PORT=None):
# Add startswith methods so we can perform lookups from the frontend
SAFRSBase.startswith = startswith
# Needed because we don't want to implicitly commit when using flask-admin
SAFRSBase.db_commit = False
with app.app_context():
db.init_app(app)
db.create_all()
# populate the database
NR_INSTANCES = 200
for i in range(NR_INSTANCES):
reader = Person(name="Reader " + str(i), email="reader@email" + str(i), password=hashlib.sha256(bytes(i)).hexdigest())
author = Person(name="Author " + str(i), email="author@email" + str(i))
book = Book(title="book_title" + str(i))
review = Review(reader_id=reader.id, book_id=book.id, review="review " + str(i))
publisher = Publisher(name="publisher" + str(i))
publisher.books.append(book)
reader.books_read.append(book)
author.books_written.append(book)
reader.friends.append(author)
author.friends.append(reader)
if i % 20 == 0:
reader.comment = ""
for obj in [reader, author, book, publisher, review]:
db.session.add(obj)
db.session.commit()
custom_swagger = {
"info": {"title": "New Title"},
"securityDefinitions": {"ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "My-ApiKey"}},
} # Customized swagger will be merged
api = SAFRSAPI(
app,
host=swagger_host,
port=PORT,
prefix=API_PREFIX,
api_spec_url=API_PREFIX + "/swagger",
custom_swagger=custom_swagger,
schemes=["http", "https"],
description=description,
)
for model in [Person, Book, Review, Publisher]:
# Create an API endpoint
api.expose_object(model)
# see if we can add the flask-admin views
try:
admin = Admin(app, url="/admin")
for model in [Person, Book, Review, Publisher]:
admin.add_view(sqla.ModelView(model, db.session))
except Exception as exc:
print(f"Failed to add flask-admin view {exc}")