当前位置: 首页>>代码示例>>Python>>正文


Python sqla.ModelView方法代码示例

本文整理汇总了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)) 
开发者ID:italia,项目名称:spid-testenv2,代码行数:4,代码来源:storages.py

示例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}") 
开发者ID:thomaxxl,项目名称:safrs,代码行数:59,代码来源:demo_pythonanywhere_com.py


注:本文中的flask_admin.contrib.sqla.ModelView方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。