mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2026-03-13 10:32:25 +08:00
update README.rst and add LICENSE
This commit is contained in:
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 long2ice
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
63
README.rst
63
README.rst
@@ -10,9 +10,9 @@ FastAPI Admin
|
||||
Introduction
|
||||
============
|
||||
|
||||
fastapi-admin is a admin dashboard based on `fastapi <https://github.com/tiangolo/fastapi>`_ and `tortoise-orm <https://github.com/tortoise/tortoise-orm>`_ and `rest-admin <https://github.com/wxs77577/rest-admin>`_.
|
||||
FastAPI-admin is a admin dashboard based on `fastapi <https://github.com/tiangolo/fastapi>`_ and `tortoise-orm <https://github.com/tortoise/tortoise-orm>`_ and `rest-admin <https://github.com/wxs77577/rest-admin>`_.
|
||||
|
||||
fastapi-admin provide crud feature out-of-the-box with just a few config.
|
||||
FastAPI-admin provide crud feature out-of-the-box with just a few config.
|
||||
|
||||
Features
|
||||
========
|
||||
@@ -25,18 +25,20 @@ Features
|
||||
Screenshots
|
||||
===========
|
||||
|
||||
.. image:: ./images/login.png
|
||||
.. image:: ./images/list.png
|
||||
.. image:: ./images/view.png
|
||||
.. image:: ./images/create.png
|
||||
.. image:: https://github.com/long2ice/fastapi-admin/raw/master/images/login.png
|
||||
.. image:: https://github.com/long2ice/fastapi-admin/raw/master/images/list.png
|
||||
.. image:: https://github.com/long2ice/fastapi-admin/raw/master/images/view.png
|
||||
.. image:: https://github.com/long2ice/fastapi-admin/raw/master/images/create.png
|
||||
|
||||
|
||||
Example
|
||||
=======
|
||||
Quick Start
|
||||
===========
|
||||
|
||||
backend
|
||||
Backend
|
||||
-------
|
||||
|
||||
example
|
||||
~~~~~~~
|
||||
Only you should do is runing a fastapi app and mount admin app from fastapi-admin,then call ``init()``.
|
||||
|
||||
.. code-block:: python
|
||||
@@ -75,7 +77,7 @@ Only you should do is runing a fastapi app and mount admin app from fastapi-admi
|
||||
models='examples.models',
|
||||
site=Site(
|
||||
name='FastAPI-Admin',
|
||||
logo='https://avatars2.githubusercontent.com/u/13377178?s=460&u=d150d522579f41a52a0b3dd8ea997e0161313b6e&v=4',
|
||||
logo='https://github.com/long2ice/fastapi-admin/raw/master/front/static/img/logo.png',
|
||||
locale='en-US',
|
||||
locale_switcher=True,
|
||||
menu=[
|
||||
@@ -91,7 +93,7 @@ Only you should do is runing a fastapi app and mount admin app from fastapi-admi
|
||||
),
|
||||
Menu(
|
||||
name='User',
|
||||
url='/rest/TestUser',
|
||||
url='/rest/TestUser', #important,TestUser is same of the Model class TestUser.
|
||||
icon='fa fa-user',
|
||||
),
|
||||
Menu(
|
||||
@@ -119,15 +121,46 @@ Only you should do is runing a fastapi app and mount admin app from fastapi-admi
|
||||
if __name__ == '__main__':
|
||||
uvicorn.run('main:app', port=8000, debug=True, reload=True)
|
||||
|
||||
Enum Support
|
||||
~~~~~~~~~~~~
|
||||
When you define a enum field of tortoise-orm,like ``IntEnumField``,you can inherit ``fastapi_admin.enum.EnumMixin`` and impl ``choices()`` method,
|
||||
FastAPI-admin will auto read and display and render a ``select`` widget in front.
|
||||
|
||||
front
|
||||
.. code-block:: python
|
||||
|
||||
class Status(EnumMixin, IntEnum):
|
||||
on = 1
|
||||
off = 2
|
||||
|
||||
@classmethod
|
||||
def choices(cls):
|
||||
return {
|
||||
cls.on: 'ON',
|
||||
cls.off: 'OFF'
|
||||
}
|
||||
|
||||
Admin User Model
|
||||
~~~~~~~~~~~~~~~~
|
||||
Inherit ``fastapi_admin.models.User`` and add you own fields,then pass in ``init()``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class AdminUser(User):
|
||||
is_active = fields.BooleanField(default=False, description='Is Active')
|
||||
status = fields.IntEnumField(Status, description='User Status')
|
||||
created_at = fields.DatetimeField(auto_now_add=True)
|
||||
updated_at = fields.DatetimeField(auto_now=True)
|
||||
|
||||
|
||||
Front
|
||||
-----
|
||||
just run ``cd front && npm run serve``,more reference in `rest-admin <https://github.com/wxs77577/rest-admin>`_.
|
||||
|
||||
Just run ``cd front && npm run serve``,more reference in `rest-admin <https://github.com/wxs77577/rest-admin>`_.
|
||||
|
||||
Deployment
|
||||
==========
|
||||
1. deploy fastapi app by gunicorn+uvicorn or reference https://fastapi.tiangolo.com/deployment/.
|
||||
2. run ``npm run build`` in ``front`` dir,then copy static files in ``dists`` to you server,deployment by ``nginx``.
|
||||
1. Deploy fastapi app by gunicorn+uvicorn or reference https://fastapi.tiangolo.com/deployment/.
|
||||
2. Run ``npm run build`` in ``front`` dir,then copy static files in ``dists`` to you server,deployment by ``nginx``.
|
||||
|
||||
.. note::
|
||||
Maybe you should config ``VUE_APP_API_URL``, ``BASE_URL`` environment .etc in ``.env`` of ``front`` dir,just reference docs of `rest-admin <https://github.com/wxs77577/rest-admin>`_.
|
||||
|
||||
@@ -32,7 +32,7 @@ def create_app():
|
||||
models='examples.models',
|
||||
site=Site(
|
||||
name='FastAPI-Admin',
|
||||
logo='https://avatars2.githubusercontent.com/u/13377178?s=460&u=d150d522579f41a52a0b3dd8ea997e0161313b6e&v=4',
|
||||
logo='https://github.com/long2ice/fastapi-admin/raw/master/front/static/img/logo.png',
|
||||
locale='en-US',
|
||||
locale_switcher=True,
|
||||
menu=[
|
||||
|
||||
@@ -25,6 +25,14 @@ class AdminApp(FastAPI):
|
||||
}
|
||||
|
||||
def init(self, site: Site, user_model: str, admin_secret: str, models: str, ):
|
||||
"""
|
||||
init admin site
|
||||
:param site:
|
||||
:param user_model: admin user model path,like admin.models.user
|
||||
:param admin_secret: admin jwt secret.
|
||||
:param models: tortoise models
|
||||
:return:
|
||||
"""
|
||||
self.site = site
|
||||
self.admin_secret = admin_secret
|
||||
self.models = importlib.import_module(models)
|
||||
@@ -32,6 +40,12 @@ class AdminApp(FastAPI):
|
||||
self._inited = True
|
||||
|
||||
def _exclude_field(self, resource: str, field: str):
|
||||
"""
|
||||
exclude field by menu include and exclude
|
||||
:param resource:
|
||||
:param field:
|
||||
:return:
|
||||
"""
|
||||
for menu in filter(lambda x: x.url, self.site.menus):
|
||||
if resource == menu.url.split('?')[0].split('/')[-1]:
|
||||
if menu.include:
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 416 KiB After Width: | Height: | Size: 185 KiB |
BIN
images/list.png
BIN
images/list.png
Binary file not shown.
|
Before Width: | Height: | Size: 492 KiB After Width: | Height: | Size: 256 KiB |
BIN
images/view.png
BIN
images/view.png
Binary file not shown.
|
Before Width: | Height: | Size: 447 KiB After Width: | Height: | Size: 212 KiB |
6
setup.py
6
setup.py
@@ -8,7 +8,7 @@ with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f:
|
||||
|
||||
|
||||
def requirements():
|
||||
return open("requirements.txt", "rt").read().splitlines()
|
||||
return open('requirements.txt', 'rt').read().splitlines()
|
||||
|
||||
|
||||
setup(
|
||||
@@ -21,11 +21,11 @@ setup(
|
||||
author_email='long2ice@gmail.com',
|
||||
url='https://github.com/long2ice/fastapi-admin',
|
||||
license='MIT License',
|
||||
packages=find_packages(include=["fastapi_admin*"]),
|
||||
packages=find_packages(include=['fastapi_admin*']),
|
||||
include_package_data=True,
|
||||
platforms='any',
|
||||
keywords=(
|
||||
"fastapi admin dashboard"
|
||||
'fastapi admin dashboard'
|
||||
),
|
||||
dependency_links=['https://github.com/long2ice/tortoise-orm.git@long2ice#egg=tortoise-orm'],
|
||||
install_requires=requirements(),
|
||||
|
||||
Reference in New Issue
Block a user