mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-15 03:04:37 +08:00
no need to import Role and Permission
This commit is contained in:
48
README.rst
48
README.rst
@ -91,6 +91,8 @@ Backend Integration
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
from fastapi_admin.factory import app as admin_app
|
||||||
|
|
||||||
fast_app = FastAPI()
|
fast_app = FastAPI()
|
||||||
|
|
||||||
register_tortoise(fast_app, config=TORTOISE_ORM, generate_schemas=True)
|
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``.
|
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
|
.. 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):
|
class AdminUser(AdminUser,Model):
|
||||||
is_active = fields.BooleanField(default=False, description='Is Active')
|
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)
|
created_at = fields.DatetimeField(auto_now_add=True)
|
||||||
updated_at = fields.DatetimeField(auto_now=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
|
TORTOISE_ORM = {
|
||||||
|
'connections': {
|
||||||
$ fastapi-admin -h
|
'default': os.getenv('DATABASE_URL')
|
||||||
usage: fastapi-admin [-h] -c CONFIG {register_permissions,createsuperuser} ...
|
},
|
||||||
|
'apps': {
|
||||||
optional arguments:
|
'models': {
|
||||||
-h, --help show this help message and exit
|
'models': ['examples.models', 'fastapi_admin.models'],
|
||||||
-c CONFIG, --config CONFIG
|
'default_connection': 'default',
|
||||||
Tortoise-orm config dict import path,like settings.TORTOISE_ORM.
|
}
|
||||||
|
}
|
||||||
subcommands:
|
}
|
||||||
{register_permissions,createsuperuser}
|
|
||||||
|
|
||||||
And set ``permission=True`` to active it:
|
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
|
Enum Support
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
When you define a enum field of tortoise-orm,like ``IntEnumField``,you can inherit ``fastapi_admin.enums.EnumMixin`` and impl ``choices()`` method,
|
When you define a enum field of tortoise-orm,like ``IntEnumField``,you can inherit ``fastapi_admin.enums.EnumMixin`` and impl ``choices()`` method,
|
||||||
|
@ -18,7 +18,7 @@ TORTOISE_ORM = {
|
|||||||
},
|
},
|
||||||
'apps': {
|
'apps': {
|
||||||
'models': {
|
'models': {
|
||||||
'models': ['examples.models'],
|
'models': ['examples.models', 'fastapi_admin.models'],
|
||||||
'default_connection': 'default',
|
'default_connection': 'default',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ async def start_up():
|
|||||||
admin_secret='test',
|
admin_secret='test',
|
||||||
permission=True,
|
permission=True,
|
||||||
site=Site(
|
site=Site(
|
||||||
name='FastAPI-admin Demo',
|
name='FastAPI-Admin DEMO',
|
||||||
logo='https://github.com/long2ice/fastapi-admin/raw/master/front/static/img/logo.png',
|
logo='https://github.com/long2ice/fastapi-admin/raw/master/front/static/img/logo.png',
|
||||||
login_footer='FASTAPI ADMIN - FastAPI Admin Dashboard',
|
login_footer='FASTAPI ADMIN - FastAPI Admin Dashboard',
|
||||||
login_description='FastAPI Admin Dashboard',
|
login_description='FastAPI Admin Dashboard',
|
||||||
|
@ -2,7 +2,7 @@ import datetime
|
|||||||
|
|
||||||
from tortoise import fields, Model
|
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
|
from .enums import ProductType, Status
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user