當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。