From dfdfaaa9ea99f973e3d558a0e85b382d37a0b15e Mon Sep 17 00:00:00 2001 From: long2ice Date: Sun, 17 May 2020 21:55:11 +0800 Subject: [PATCH] no need to import Role and Permission --- README.rst | 48 ++++++++++++++++++++++++++++++---------------- examples/main.py | 4 ++-- examples/models.py | 2 +- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/README.rst b/README.rst index b0b90ea..05c5ca2 100644 --- a/README.rst +++ b/README.rst @@ -91,6 +91,8 @@ Backend Integration .. code-block:: python + from fastapi_admin.factory import app as admin_app + fast_app = FastAPI() register_tortoise(fast_app, config=TORTOISE_ORM, generate_schemas=True) @@ -118,11 +120,9 @@ Builtin Auth And Permissions Control ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Inherit ``fastapi_admin.models.User`` and add you own fields,must contains ``is_active`` and ``is_superuser``. -And you must import ``Permission`` and ``Role``, just import and do nothing: - .. code-block:: python - from fastapi_admin.models import User as AdminUser, Permission, Role + from fastapi_admin.models import User as AdminUser class AdminUser(AdminUser,Model): is_active = fields.BooleanField(default=False, description='Is Active') @@ -131,21 +131,21 @@ And you must import ``Permission`` and ``Role``, just import and do nothing: created_at = fields.DatetimeField(auto_now_add=True) updated_at = fields.DatetimeField(auto_now=True) +Then add ``fastapi_admin.models`` to ``Tortoise-ORM`` config, example: -Then register permissions and createsuperuser: +.. code-block:: python -.. code-block:: shell - - $ fastapi-admin -h - usage: fastapi-admin [-h] -c CONFIG {register_permissions,createsuperuser} ... - - optional arguments: - -h, --help show this help message and exit - -c CONFIG, --config CONFIG - Tortoise-orm config dict import path,like settings.TORTOISE_ORM. - - subcommands: - {register_permissions,createsuperuser} + TORTOISE_ORM = { + 'connections': { + 'default': os.getenv('DATABASE_URL') + }, + 'apps': { + 'models': { + 'models': ['examples.models', 'fastapi_admin.models'], + 'default_connection': 'default', + } + } + } And set ``permission=True`` to active it: @@ -161,6 +161,22 @@ And set ``permission=True`` to active it: ) ) +And register permissions and createsuperuser: + +.. code-block:: shell + + $ fastapi-admin -h + usage: fastapi-admin [-h] -c CONFIG {register_permissions,createsuperuser} ... + + optional arguments: + -h, --help show this help message and exit + -c CONFIG, --config CONFIG + Tortoise-orm config dict import path,like settings.TORTOISE_ORM. + + subcommands: + {register_permissions,createsuperuser} + + Enum Support ~~~~~~~~~~~~ When you define a enum field of tortoise-orm,like ``IntEnumField``,you can inherit ``fastapi_admin.enums.EnumMixin`` and impl ``choices()`` method, diff --git a/examples/main.py b/examples/main.py index 79f35c0..1a41876 100644 --- a/examples/main.py +++ b/examples/main.py @@ -18,7 +18,7 @@ TORTOISE_ORM = { }, 'apps': { 'models': { - 'models': ['examples.models'], + 'models': ['examples.models', 'fastapi_admin.models'], 'default_connection': 'default', } } @@ -77,7 +77,7 @@ async def start_up(): admin_secret='test', permission=True, site=Site( - name='FastAPI-admin Demo', + name='FastAPI-Admin DEMO', logo='https://github.com/long2ice/fastapi-admin/raw/master/front/static/img/logo.png', login_footer='FASTAPI ADMIN - FastAPI Admin Dashboard', login_description='FastAPI Admin Dashboard', diff --git a/examples/models.py b/examples/models.py index 6e558bd..d1a5d0c 100644 --- a/examples/models.py +++ b/examples/models.py @@ -2,7 +2,7 @@ import datetime from tortoise import fields, Model -from fastapi_admin.models import User as AdminUser, Permission, Role +from fastapi_admin.models import User as AdminUser from .enums import ProductType, Status