mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-14 18:58:13 +08:00
update docs
This commit is contained in:
41
.github/workflows/deploy.yml
vendored
Normal file
41
.github/workflows/deploy.yml
vendored
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
name: deploy
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
example:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Deploy
|
||||||
|
uses: appleboy/ssh-action@master
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.HOST }}
|
||||||
|
username: ${{ secrets.USERNAME }}
|
||||||
|
key: ${{ secrets.KEY }}
|
||||||
|
port: ${{ secrets.PORT }}
|
||||||
|
script: |
|
||||||
|
cd /root/fastapi-admin/
|
||||||
|
git pull
|
||||||
|
docker-compose up -d --build
|
||||||
|
gh-pages:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install and configure Poetry
|
||||||
|
uses: snok/install-poetry@v1.1.1
|
||||||
|
with:
|
||||||
|
virtualenvs-create: false
|
||||||
|
- name: Install deps
|
||||||
|
run: make deps
|
||||||
|
- name: Build en
|
||||||
|
run: cd docs/en && mkdocs build
|
||||||
|
- name: Deploy en
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: docs/en/site
|
||||||
|
- name: Build zh
|
||||||
|
run: cd docs/zh && mkdocs build
|
||||||
|
- name: Deploy zh
|
||||||
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
publish_dir: docs/zh/site
|
||||||
|
destination_dir: zh
|
2
.github/workflows/pypi.yml
vendored
2
.github/workflows/pypi.yml
vendored
@ -10,7 +10,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v1
|
||||||
with:
|
with:
|
||||||
python-version: '3.x'
|
python-version: "3.x"
|
||||||
- name: Install and configure Poetry
|
- name: Install and configure Poetry
|
||||||
uses: snok/install-poetry@v1.1.1
|
uses: snok/install-poetry@v1.1.1
|
||||||
with:
|
with:
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -120,7 +120,7 @@ venv.bak/
|
|||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
# mkdocs documentation
|
# mkdocs documentation
|
||||||
/site
|
site/
|
||||||
|
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.7
|
FROM python:3
|
||||||
RUN mkdir -p /fastapi-admin
|
RUN mkdir -p /fastapi-admin
|
||||||
WORKDIR /fastapi-admin
|
WORKDIR /fastapi-admin
|
||||||
COPY pyproject.toml poetry.lock /fastapi-admin/
|
COPY pyproject.toml poetry.lock /fastapi-admin/
|
||||||
|
@ -1,21 +1,11 @@
|
|||||||
version: '3'
|
version: "3"
|
||||||
services:
|
services:
|
||||||
mysql:
|
app:
|
||||||
image: mysql
|
|
||||||
environment:
|
|
||||||
MYSQL_ROOT_PASSWORD: 123456
|
|
||||||
MYSQL_DATABASE: fastapi-admin
|
|
||||||
healthcheck:
|
|
||||||
test: --health-cmd "mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 10
|
|
||||||
api:
|
|
||||||
build: .
|
build: .
|
||||||
restart: always
|
restart: always
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: mysql://root:123456@mysql:3306/fastapi-admin
|
DATABASE_URL: mysql://root:123456@127.0.0.1:3306/fastapi-admin
|
||||||
TZ: Asia/Shanghai
|
TZ: Asia/Shanghai
|
||||||
ports:
|
network_mode: host
|
||||||
- '8000:8000'
|
|
||||||
depends_on:
|
|
||||||
- mysql
|
|
||||||
image: fastapi-admin
|
image: fastapi-admin
|
||||||
command: uvicorn examples.main:app --port 8000 --host 0.0.0.0
|
command: uvicorn examples.main:app --port 8000 --host 0.0.0.0
|
||||||
|
1
docs/en/docs/custom/file.md
Normal file
1
docs/en/docs/custom/file.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# File Upload Provider
|
1
docs/en/docs/custom/login.md
Normal file
1
docs/en/docs/custom/login.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Login Provider
|
1
docs/en/docs/custom/overwrite.md
Normal file
1
docs/en/docs/custom/overwrite.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Override builtin pages and widgets
|
1
docs/en/docs/custom/page.md
Normal file
1
docs/en/docs/custom/page.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Custom Page
|
1
docs/en/docs/custom/widget.md
Normal file
1
docs/en/docs/custom/widget.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Widget
|
@ -66,14 +66,102 @@ class Home(Link):
|
|||||||
url = "/admin"
|
url = "/admin"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Field
|
|
||||||
|
|
||||||
The `Field` is used in `Model` resource to define how to display and input every field in model.
|
|
||||||
|
|
||||||
### Model
|
### Model
|
||||||
|
|
||||||
The `Model` make a TortoiseORM model as a menu with CURD actions.
|
#### Field
|
||||||
|
|
||||||
|
The `Field` is used in `Model` resource to define how to display and input every field in model page.
|
||||||
|
|
||||||
|
The `Model` make a TortoiseORM model as a menu with CURD page.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
from examples.models import User
|
||||||
|
from fastapi_admin.app import app
|
||||||
|
from fastapi_admin.resources import Field, Model
|
||||||
|
from fastapi_admin.widgets import displays, filters, inputs
|
||||||
|
|
||||||
|
|
||||||
|
@app.register
|
||||||
|
class UserResource(Model):
|
||||||
|
label = "User"
|
||||||
|
model = User
|
||||||
|
icon = "ti ti-user"
|
||||||
|
page_pre_title = "user list"
|
||||||
|
page_title = "user model"
|
||||||
|
filters = [
|
||||||
|
filters.Search(
|
||||||
|
name="username", label="Name", search_mode="contains", placeholder="Search for username"
|
||||||
|
),
|
||||||
|
filters.Date(name="created_at", label="CreatedAt"),
|
||||||
|
]
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"username",
|
||||||
|
Field(
|
||||||
|
name="password",
|
||||||
|
label="Password",
|
||||||
|
display=displays.InputOnly(),
|
||||||
|
input_=inputs.Password(),
|
||||||
|
),
|
||||||
|
Field(name="email", label="Email", input_=inputs.Email()),
|
||||||
|
Field(
|
||||||
|
name="avatar",
|
||||||
|
label="Avatar",
|
||||||
|
display=displays.Image(width="40"),
|
||||||
|
input_=inputs.Image(null=True, upload_provider=upload_provider),
|
||||||
|
),
|
||||||
|
"is_superuser",
|
||||||
|
"is_active",
|
||||||
|
"created_at",
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
### Dropdown
|
### Dropdown
|
||||||
|
|
||||||
The `Dropdown` can contains both `Link` and `Model`, which can be nested.
|
The `Dropdown` can contains both `Link` and `Model`, which can be nested.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
|
||||||
|
from examples import enums
|
||||||
|
from examples.models import Category, Product
|
||||||
|
from fastapi_admin.app import app
|
||||||
|
from fastapi_admin.resources import Dropdown, Field, Model
|
||||||
|
from fastapi_admin.widgets import displays, filters
|
||||||
|
|
||||||
|
|
||||||
|
@app.register
|
||||||
|
class Content(Dropdown):
|
||||||
|
class CategoryResource(Model):
|
||||||
|
label = "Category"
|
||||||
|
model = Category
|
||||||
|
fields = ["id", "name", "slug", "created_at"]
|
||||||
|
|
||||||
|
class ProductResource(Model):
|
||||||
|
label = "Product"
|
||||||
|
model = Product
|
||||||
|
filters = [
|
||||||
|
filters.Enum(enum=enums.ProductType, name="type", label="ProductType"),
|
||||||
|
filters.Datetime(name="created_at", label="CreatedAt"),
|
||||||
|
]
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"view_num",
|
||||||
|
"sort",
|
||||||
|
"is_reviewed",
|
||||||
|
"type",
|
||||||
|
Field(name="image", label="Image", display=displays.Image(width="40")),
|
||||||
|
"body",
|
||||||
|
"created_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
label = "Content"
|
||||||
|
icon = "ti ti-package"
|
||||||
|
resources = [ProductResource, CategoryResource]
|
||||||
|
```
|
||||||
|
|
||||||
|
### What's next?
|
||||||
|
|
||||||
|
That's all, you can run your app now. For more reference you can see [Reference](/reference).
|
||||||
|
@ -1,15 +1,59 @@
|
|||||||
# Content
|
# Exclusive content
|
||||||
|
|
||||||
## Login Captcha
|
## Login Captcha
|
||||||
|
|
||||||
|
You can set captcha in admin login page, just set `enable_captcha=True`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
login_provider = UsernamePasswordProvider(user_model=User, enable_captcha=True)
|
||||||
|
```
|
||||||
|
|
||||||
## Failed Login IP Limitation
|
## Failed Login IP Limitation
|
||||||
|
|
||||||
|
If you want limit login failed ip with error password, you can use `LoginPasswordMaxTryMiddleware`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
admin_app.add_middleware(BaseHTTPMiddleware, dispatch=LoginPasswordMaxTryMiddleware(max_times = 3, after_seconds = 360))
|
||||||
|
```
|
||||||
|
|
||||||
## Additional File Upload Providers
|
## Additional File Upload Providers
|
||||||
|
|
||||||
|
### ALiYunOSSProvider
|
||||||
|
|
||||||
|
### AwsS3Provider
|
||||||
|
|
||||||
## Error pages
|
## Error pages
|
||||||
|
|
||||||
|
### 404
|
||||||
|
|
||||||
|
You can catch all `404` error to show builtin `404` page.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fastapi_admin.exceptions import not_found_error_exception
|
||||||
|
from starlette.status import HTTP_404_NOT_FOUND
|
||||||
|
|
||||||
|
app.add_exception_handler(HTTP_404_NOT_FOUND, not_found_error_exception)
|
||||||
|
```
|
||||||
|
|
||||||
|
### 500
|
||||||
|
|
||||||
|
You can catch all `500` error to show builtin `500` page.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR
|
||||||
|
from fastapi_admin.exceptions import server_error_exception
|
||||||
|
|
||||||
|
app.add_exception_handler(HTTP_500_INTERNAL_SERVER_ERROR, server_error_exception)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Maintenance
|
||||||
|
|
||||||
|
If your site is in maintenance, you can set `true` to `admin_app.configure(...)`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
admin_app.configure(maintenance=True)
|
||||||
|
```
|
||||||
|
|
||||||
## Free consultation
|
## Free consultation
|
||||||
|
|
||||||
## Others
|
Whenever you have any questions, you can send email to <long2ice@gmai.com> or open `issue` in `fastapi-admin-pro` repository, I will answer your questions as soon as possible.
|
||||||
|
|
||||||
...
|
|
||||||
|
@ -1 +1,34 @@
|
|||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
|
Because pro version won't publish to pypi, so you can't install from it.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
In order to access the repository programmatically (from the command line or GitHub Actions workflows), you need to create a personal access token:
|
||||||
|
|
||||||
|
1. Go to <https://github.com/settings/tokens>.
|
||||||
|
2. Click on Generate a new token.
|
||||||
|
3. Enter a name and select the repo scope.
|
||||||
|
4. Generate the token and store it in a safe place.
|
||||||
|
|
||||||
|
## With pip
|
||||||
|
|
||||||
|
```shell
|
||||||
|
> pip install git+https://${GH_TOKEN}@github.com/fastapi-admin/fastapi-admin-pro.git
|
||||||
|
```
|
||||||
|
|
||||||
|
## With poetry
|
||||||
|
|
||||||
|
Add the following line in section `[tool.poetry.dependencies]`.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
fastapi-admin-pro = { git = 'https://${GH_TOKEN}@github.com/fastapi-admin/fastapi-admin-pro.git', branch = 'develop' }
|
||||||
|
```
|
||||||
|
|
||||||
|
## In requirements.txt
|
||||||
|
|
||||||
|
Add the following line.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
-e https://${GH_TOKEN}@github.com/fastapi-admin/fastapi-admin-pro.git@develop#egg=fastapi-admin-pro
|
||||||
|
```
|
||||||
|
@ -1 +1,23 @@
|
|||||||
# Sponsor
|
# Sponsor
|
||||||
|
|
||||||
|
The pro version is just for the sponsors. As a sponsor, you will be invited to [fastapi-admin](https://github.com/fastapi-admin) organization as a outside collaborator with readonly access, and you can get the pro features and get updates for a time.
|
||||||
|
|
||||||
|
## How to become a sponsor
|
||||||
|
|
||||||
|
Sponsor Link: <http://sponsor.long2ice.cn>
|
||||||
|
|
||||||
|
You can choice any sponsor way you like. After sponsor, you can email me <long2ice@gmail.com> with your github account and sponsor way and account, then I will invite you to join [fastapi-admin](https://github.com/fastapi-admin) organization.
|
||||||
|
|
||||||
|
## Levels
|
||||||
|
|
||||||
|
### $10 - Month
|
||||||
|
|
||||||
|
You will be invited and keep collaborator role for a month.
|
||||||
|
|
||||||
|
### $50 - Half a Year
|
||||||
|
|
||||||
|
You will be invited and keep collaborator role for half a year.
|
||||||
|
|
||||||
|
### $90 - Year
|
||||||
|
|
||||||
|
You will be invited and keep collaborator role for a year.
|
||||||
|
@ -1 +1,43 @@
|
|||||||
# Configuration
|
# Configuration
|
||||||
|
|
||||||
|
The following configurations can be used to `admin_app.configure(...)`.
|
||||||
|
|
||||||
|
## logo_url
|
||||||
|
|
||||||
|
Will show the logo image in admin dashboard.
|
||||||
|
|
||||||
|
## login_logo_url
|
||||||
|
|
||||||
|
Will show the logo in login page.
|
||||||
|
|
||||||
|
## admin_path
|
||||||
|
|
||||||
|
Default is `/admin`, but you can change to other page.
|
||||||
|
|
||||||
|
## maintenance (💗 Pro only)
|
||||||
|
|
||||||
|
If set to `true`, all pages will be redirected to the `/maintenance` page.
|
||||||
|
|
||||||
|
## redis
|
||||||
|
|
||||||
|
Instance of `aioredis`.
|
||||||
|
|
||||||
|
## default_locale
|
||||||
|
|
||||||
|
Current support `zh` and `en`, default is `en`.
|
||||||
|
|
||||||
|
## template_folders
|
||||||
|
|
||||||
|
Template folders used to override builtin templates.
|
||||||
|
|
||||||
|
## login_provider
|
||||||
|
|
||||||
|
You can pass subclasses of `fastapi_admin.providers.login.LoginProvider`, there is a builtin `fastapi_admin.providers.login.UsernamePasswordProvider` you can use.
|
||||||
|
|
||||||
|
### user_model
|
||||||
|
|
||||||
|
Subclass instance of `fastapi_admin.providers.login.UserMixin`.
|
||||||
|
|
||||||
|
### enable_captcha (💗 Pro only)
|
||||||
|
|
||||||
|
Show captcha in admin login page.
|
||||||
|
@ -1 +1,7 @@
|
|||||||
# File Upload
|
# File Upload
|
||||||
|
|
||||||
|
## FileUploadProvider
|
||||||
|
|
||||||
|
## ALiYunOSSProvider (💗 Pro only)
|
||||||
|
|
||||||
|
## AwsS3Provider (💗 Pro only)
|
||||||
|
@ -1 +1,3 @@
|
|||||||
# Middleware
|
# Middleware
|
||||||
|
|
||||||
|
## LoginPasswordMaxTryMiddleware (💗 Pro only)
|
||||||
|
@ -1 +1,9 @@
|
|||||||
# Resource
|
# Resource
|
||||||
|
|
||||||
|
## Link
|
||||||
|
|
||||||
|
## Model
|
||||||
|
|
||||||
|
### Field
|
||||||
|
|
||||||
|
## Dropdown
|
||||||
|
@ -48,8 +48,12 @@ nav:
|
|||||||
- reference/widget/input.md
|
- reference/widget/input.md
|
||||||
- reference/file_upload.md
|
- reference/file_upload.md
|
||||||
- reference/middleware.md
|
- reference/middleware.md
|
||||||
- Extension:
|
- Custom:
|
||||||
- extension/index.md
|
- custom/page.md
|
||||||
|
- custom/overwrite.md
|
||||||
|
- custom/login.md
|
||||||
|
- custom/file.md
|
||||||
|
- custom/widget.md
|
||||||
- Pro Version For Sponsor:
|
- Pro Version For Sponsor:
|
||||||
- pro/index.md
|
- pro/index.md
|
||||||
- pro/sponsor.md
|
- pro/sponsor.md
|
||||||
@ -67,7 +71,7 @@ extra:
|
|||||||
copyright: Copyright © 2021 long2ice
|
copyright: Copyright © 2021 long2ice
|
||||||
|
|
||||||
plugins:
|
plugins:
|
||||||
|
- search
|
||||||
- git-revision-date-localized:
|
- git-revision-date-localized:
|
||||||
type: datetime
|
type: datetime
|
||||||
- markdownextradata
|
|
||||||
dev_addr: 127.0.0.1:7999
|
dev_addr: 127.0.0.1:7999
|
||||||
|
1
docs/zh/docs/getting_started/index.md
Symbolic link
1
docs/zh/docs/getting_started/index.md
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../../../README.md
|
33
docs/zh/docs/getting_started/installation.md
Normal file
33
docs/zh/docs/getting_started/installation.md
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
# Installation
|
||||||
|
|
||||||
|
## From pypi
|
||||||
|
|
||||||
|
You can install from pypi.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
> pip install fastapi-admin
|
||||||
|
```
|
||||||
|
|
||||||
|
## From source
|
||||||
|
|
||||||
|
Or you can install from source with latest code.
|
||||||
|
|
||||||
|
```shell
|
||||||
|
> pip install git+https://github.com/fastapi-admin/fastapi-admin.git
|
||||||
|
```
|
||||||
|
|
||||||
|
### With requirements.txt
|
||||||
|
|
||||||
|
Add the following line.
|
||||||
|
|
||||||
|
```
|
||||||
|
-e https://github.com/fastapi-admin/fastapi-admin.git@develop#egg=fastapi-admin
|
||||||
|
```
|
||||||
|
|
||||||
|
### With poetry
|
||||||
|
|
||||||
|
Add the following line in section `[tool.poetry.dependencies]`.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
fastapi-admin = { git = 'https://github.com/fastapi-admin/fastapi-admin.git', branch = 'develop' }
|
||||||
|
```
|
167
docs/zh/docs/getting_started/quickstart.md
Normal file
167
docs/zh/docs/getting_started/quickstart.md
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
# Quickstart
|
||||||
|
|
||||||
|
`FastAPI-Admin` is easy to mount your `FastAPI` app, just need a few configs.
|
||||||
|
|
||||||
|
## Mount Admin App
|
||||||
|
|
||||||
|
First, you need mount the admin app from `FastAPI-Admin` as a sub application of `FastAPI`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fastapi_admin.app import app as admin_app
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
app.mount("/admin", admin_app)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Configure Admin App
|
||||||
|
|
||||||
|
There are some configs to configure the admin app, and you need to configure it on startup of `FastAPI`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fastapi_admin.app import app as admin_app
|
||||||
|
from fastapi_admin.providers.login import UsernamePasswordProvider
|
||||||
|
from examples.models import User
|
||||||
|
import aioredis
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
login_provider = UsernamePasswordProvider(user_model=User, enable_captcha=True)
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
|
@app.on_event("startup")
|
||||||
|
async def startup():
|
||||||
|
redis = await aioredis.create_redis_pool("redis://localhost", encoding="utf8")
|
||||||
|
admin_app.configure(
|
||||||
|
logo_url="https://preview.tabler.io/static/logo-white.svg",
|
||||||
|
login_logo_url="https://preview.tabler.io/static/logo.svg",
|
||||||
|
template_folders=[os.path.join(BASE_DIR, "templates")],
|
||||||
|
login_provider=login_provider,
|
||||||
|
maintenance=False,
|
||||||
|
redis=redis,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
The full list of configs and detail can be found in [Configuration](/reference/configuration).
|
||||||
|
|
||||||
|
## Define And Register Resource
|
||||||
|
|
||||||
|
There are three kinds of resources, which are `Link`,`Model`, and `Dropdown`.
|
||||||
|
|
||||||
|
### Link
|
||||||
|
|
||||||
|
The `Link` will display a menu in sidebar with custom page or third page.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from fastapi_admin.app import app
|
||||||
|
from fastapi_admin.resources import Link
|
||||||
|
|
||||||
|
|
||||||
|
@app.register
|
||||||
|
class Home(Link):
|
||||||
|
label = "Home"
|
||||||
|
icon = "ti ti-home"
|
||||||
|
url = "/admin"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Field
|
||||||
|
|
||||||
|
The `Field` is used in `Model` resource to define how to display and input every field in model page.
|
||||||
|
|
||||||
|
### Model
|
||||||
|
|
||||||
|
The `Model` make a TortoiseORM model as a menu with CURD page.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
from examples.models import User
|
||||||
|
from fastapi_admin.app import app
|
||||||
|
from fastapi_admin.resources import Field, Model
|
||||||
|
from fastapi_admin.widgets import displays, filters, inputs
|
||||||
|
|
||||||
|
|
||||||
|
@app.register
|
||||||
|
class UserResource(Model):
|
||||||
|
label = "User"
|
||||||
|
model = User
|
||||||
|
icon = "ti ti-user"
|
||||||
|
page_pre_title = "user list"
|
||||||
|
page_title = "user model"
|
||||||
|
filters = [
|
||||||
|
filters.Search(
|
||||||
|
name="username", label="Name", search_mode="contains", placeholder="Search for username"
|
||||||
|
),
|
||||||
|
filters.Date(name="created_at", label="CreatedAt"),
|
||||||
|
]
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"username",
|
||||||
|
Field(
|
||||||
|
name="password",
|
||||||
|
label="Password",
|
||||||
|
display=displays.InputOnly(),
|
||||||
|
input_=inputs.Password(),
|
||||||
|
),
|
||||||
|
Field(name="email", label="Email", input_=inputs.Email()),
|
||||||
|
Field(
|
||||||
|
name="avatar",
|
||||||
|
label="Avatar",
|
||||||
|
display=displays.Image(width="40"),
|
||||||
|
input_=inputs.Image(null=True, upload_provider=upload_provider),
|
||||||
|
),
|
||||||
|
"is_superuser",
|
||||||
|
"is_active",
|
||||||
|
"created_at",
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Dropdown
|
||||||
|
|
||||||
|
The `Dropdown` can contains both `Link` and `Model`, which can be nested.
|
||||||
|
|
||||||
|
```python
|
||||||
|
|
||||||
|
|
||||||
|
from examples import enums
|
||||||
|
from examples.models import Category, Product
|
||||||
|
from fastapi_admin.app import app
|
||||||
|
from fastapi_admin.resources import Dropdown, Field, Model
|
||||||
|
from fastapi_admin.widgets import displays, filters
|
||||||
|
|
||||||
|
|
||||||
|
@app.register
|
||||||
|
class Content(Dropdown):
|
||||||
|
class CategoryResource(Model):
|
||||||
|
label = "Category"
|
||||||
|
model = Category
|
||||||
|
fields = ["id", "name", "slug", "created_at"]
|
||||||
|
|
||||||
|
class ProductResource(Model):
|
||||||
|
label = "Product"
|
||||||
|
model = Product
|
||||||
|
filters = [
|
||||||
|
filters.Enum(enum=enums.ProductType, name="type", label="ProductType"),
|
||||||
|
filters.Datetime(name="created_at", label="CreatedAt"),
|
||||||
|
]
|
||||||
|
fields = [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"view_num",
|
||||||
|
"sort",
|
||||||
|
"is_reviewed",
|
||||||
|
"type",
|
||||||
|
Field(name="image", label="Image", display=displays.Image(width="40")),
|
||||||
|
"body",
|
||||||
|
"created_at",
|
||||||
|
]
|
||||||
|
|
||||||
|
label = "Content"
|
||||||
|
icon = "ti ti-package"
|
||||||
|
resources = [ProductResource, CategoryResource]
|
||||||
|
```
|
||||||
|
|
||||||
|
### What's next?
|
||||||
|
|
||||||
|
That's all, you can run your app now. For more reference you can see [Reference](/reference).
|
15
docs/zh/docs/pro/index.md
Normal file
15
docs/zh/docs/pro/index.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# Content
|
||||||
|
|
||||||
|
## Login Captcha
|
||||||
|
|
||||||
|
## Failed Login IP Limitation
|
||||||
|
|
||||||
|
## Additional File Upload Providers
|
||||||
|
|
||||||
|
## Error pages
|
||||||
|
|
||||||
|
## Free consultation
|
||||||
|
|
||||||
|
## Others
|
||||||
|
|
||||||
|
...
|
1
docs/zh/docs/pro/installation.md
Normal file
1
docs/zh/docs/pro/installation.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Installation
|
1
docs/zh/docs/pro/sponsor.md
Normal file
1
docs/zh/docs/pro/sponsor.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Sponsor
|
1
docs/zh/docs/reference/configuration.md
Normal file
1
docs/zh/docs/reference/configuration.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Configuration
|
1
docs/zh/docs/reference/file_upload.md
Normal file
1
docs/zh/docs/reference/file_upload.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# File Upload
|
1
docs/zh/docs/reference/middleware.md
Normal file
1
docs/zh/docs/reference/middleware.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Middleware
|
1
docs/zh/docs/reference/resource.md
Normal file
1
docs/zh/docs/reference/resource.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Resource
|
0
docs/zh/docs/reference/widget/display.md
Normal file
0
docs/zh/docs/reference/widget/display.md
Normal file
0
docs/zh/docs/reference/widget/filter.md
Normal file
0
docs/zh/docs/reference/widget/filter.md
Normal file
0
docs/zh/docs/reference/widget/input.md
Normal file
0
docs/zh/docs/reference/widget/input.md
Normal file
@ -5,10 +5,10 @@ site_description: A fast admin dashboard based on FastAPI and TortoiseORM with t
|
|||||||
repo_name: fastapi-admin/fastapi-admin
|
repo_name: fastapi-admin/fastapi-admin
|
||||||
site_author: long2ice
|
site_author: long2ice
|
||||||
theme:
|
theme:
|
||||||
logo: https://fastapi.tiangolo.com/img/icon-white.svg
|
logo: https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/icon-white.svg
|
||||||
favicon: https://fastapi.tiangolo.com/img/favicon.png
|
favicon: https://raw.githubusercontent.com/fastapi-admin/fastapi-admin/dev/images/favicon.png
|
||||||
name: material
|
name: material
|
||||||
language: zh
|
language: en
|
||||||
icon:
|
icon:
|
||||||
repo: fontawesome/brands/github
|
repo: fontawesome/brands/github
|
||||||
palette:
|
palette:
|
||||||
@ -35,11 +35,25 @@ markdown_extensions:
|
|||||||
- pymdownx.inlinehilite
|
- pymdownx.inlinehilite
|
||||||
- pymdownx.superfences
|
- pymdownx.superfences
|
||||||
nav:
|
nav:
|
||||||
- 首页: index.md
|
|
||||||
- 入门指南:
|
- 入门指南:
|
||||||
- getting_started.md
|
- getting_started/index.md
|
||||||
- Pro 特性:
|
- getting_started/installation.md
|
||||||
|
- getting_started/quickstart.md
|
||||||
|
- 参考:
|
||||||
|
- reference/configuration.md
|
||||||
|
- reference/resource.md
|
||||||
|
- 组件:
|
||||||
|
- reference/widget/filter.md
|
||||||
|
- reference/widget/display.md
|
||||||
|
- reference/widget/input.md
|
||||||
|
- reference/file_upload.md
|
||||||
|
- reference/middleware.md
|
||||||
|
- 自定义:
|
||||||
|
- custom/index.md
|
||||||
|
- 赞助者 Pro 版本:
|
||||||
|
- pro/index.md
|
||||||
- pro/sponsor.md
|
- pro/sponsor.md
|
||||||
|
- pro/installation.md
|
||||||
extra:
|
extra:
|
||||||
alternate:
|
alternate:
|
||||||
- name: English
|
- name: English
|
||||||
@ -55,3 +69,5 @@ copyright: Copyright © 2021 long2ice
|
|||||||
plugins:
|
plugins:
|
||||||
- git-revision-date-localized:
|
- git-revision-date-localized:
|
||||||
type: datetime
|
type: datetime
|
||||||
|
- markdownextradata
|
||||||
|
dev_addr: 127.0.0.1:7999
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
import aioredis
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from starlette.middleware.cors import CORSMiddleware
|
from starlette.middleware.cors import CORSMiddleware
|
||||||
@ -11,7 +12,6 @@ from examples.constants import BASE_DIR
|
|||||||
from examples.models import User
|
from examples.models import User
|
||||||
from fastapi_admin.app import app as admin_app
|
from fastapi_admin.app import app as admin_app
|
||||||
from fastapi_admin.providers.login import UsernamePasswordProvider
|
from fastapi_admin.providers.login import UsernamePasswordProvider
|
||||||
import aioredis
|
|
||||||
|
|
||||||
login_provider = UsernamePasswordProvider(user_model=User, enable_captcha=True)
|
login_provider = UsernamePasswordProvider(user_model=User, enable_captcha=True)
|
||||||
|
|
||||||
|
25
poetry.lock
generated
25
poetry.lock
generated
@ -428,18 +428,6 @@ babel = ">=2.7.0"
|
|||||||
GitPython = "*"
|
GitPython = "*"
|
||||||
mkdocs = ">=1.0"
|
mkdocs = ">=1.0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "mkdocs-markdownextradata-plugin"
|
|
||||||
version = "0.2.4"
|
|
||||||
description = "A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template"
|
|
||||||
category = "dev"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=2.7.9,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
mkdocs = "*"
|
|
||||||
pyyaml = "*"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mkdocs-material"
|
name = "mkdocs-material"
|
||||||
version = "7.1.3"
|
version = "7.1.3"
|
||||||
@ -899,7 +887,7 @@ testing = ["pytest (>=4.6)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pyt
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.7"
|
python-versions = "^3.7"
|
||||||
content-hash = "3f9c88790071d1b81d5befdb3c20a47ca70a111be58492dae51ffca81b5283e1"
|
content-hash = "c3b7114e0cfcc5ec6fb8cfb066a61922096068d0e9ff2e60b69f2162e5d2ab44"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
aiofiles = [
|
aiofiles = [
|
||||||
@ -1200,9 +1188,6 @@ mkdocs-git-revision-date-localized-plugin = [
|
|||||||
{file = "mkdocs-git-revision-date-localized-plugin-0.9.tar.gz", hash = "sha256:49e59396f1e83264b8f54fcb339a9137925a1af19e639f03dc59dae7f22e914f"},
|
{file = "mkdocs-git-revision-date-localized-plugin-0.9.tar.gz", hash = "sha256:49e59396f1e83264b8f54fcb339a9137925a1af19e639f03dc59dae7f22e914f"},
|
||||||
{file = "mkdocs_git_revision_date_localized_plugin-0.9-py3-none-any.whl", hash = "sha256:5d319398e9ce325d02df1cba232a92b215f8d0c0ffd3810b6a61d6c5eb6306e6"},
|
{file = "mkdocs_git_revision_date_localized_plugin-0.9-py3-none-any.whl", hash = "sha256:5d319398e9ce325d02df1cba232a92b215f8d0c0ffd3810b6a61d6c5eb6306e6"},
|
||||||
]
|
]
|
||||||
mkdocs-markdownextradata-plugin = [
|
|
||||||
{file = "mkdocs_markdownextradata_plugin-0.2.4-py3-none-any.whl", hash = "sha256:9acf1860488e8e990c77de2af2e575b36dfc2a24c46ac63789315f78d2a3b709"},
|
|
||||||
]
|
|
||||||
mkdocs-material = [
|
mkdocs-material = [
|
||||||
{file = "mkdocs-material-7.1.3.tar.gz", hash = "sha256:e34bba93ad1a0e6f9afc371f4ef55bedabbf13b9a786b013b0ce26ac55ec2932"},
|
{file = "mkdocs-material-7.1.3.tar.gz", hash = "sha256:e34bba93ad1a0e6f9afc371f4ef55bedabbf13b9a786b013b0ce26ac55ec2932"},
|
||||||
{file = "mkdocs_material-7.1.3-py2.py3-none-any.whl", hash = "sha256:437638b0de7a9113d7f1c9ddc93c0a29a3b808c71c3606713d8c1fa437697a3e"},
|
{file = "mkdocs_material-7.1.3-py2.py3-none-any.whl", hash = "sha256:437638b0de7a9113d7f1c9ddc93c0a29a3b808c71c3606713d8c1fa437697a3e"},
|
||||||
@ -1353,18 +1338,26 @@ pyyaml = [
|
|||||||
{file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"},
|
{file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"},
|
||||||
{file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"},
|
{file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"},
|
||||||
{file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"},
|
{file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"},
|
||||||
|
{file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"},
|
||||||
|
{file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"},
|
||||||
{file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"},
|
{file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"},
|
||||||
{file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"},
|
{file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"},
|
||||||
{file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"},
|
{file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"},
|
||||||
{file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"},
|
{file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"},
|
||||||
|
{file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"},
|
||||||
|
{file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"},
|
||||||
{file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"},
|
{file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"},
|
||||||
{file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"},
|
{file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"},
|
||||||
{file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"},
|
{file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"},
|
||||||
{file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"},
|
{file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"},
|
||||||
|
{file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"},
|
||||||
|
{file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"},
|
||||||
{file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"},
|
{file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"},
|
||||||
{file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"},
|
{file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"},
|
||||||
{file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"},
|
{file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"},
|
||||||
{file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"},
|
{file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"},
|
||||||
|
{file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"},
|
||||||
|
{file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"},
|
||||||
{file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"},
|
{file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"},
|
||||||
{file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"},
|
{file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"},
|
||||||
{file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"},
|
{file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"},
|
||||||
|
@ -45,7 +45,6 @@ asyncmy = "*"
|
|||||||
mkdocs = "*"
|
mkdocs = "*"
|
||||||
mkdocs-material = "*"
|
mkdocs-material = "*"
|
||||||
mkdocs-git-revision-date-localized-plugin = "*"
|
mkdocs-git-revision-date-localized-plugin = "*"
|
||||||
mkdocs-markdownextradata-plugin = "*"
|
|
||||||
|
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["poetry-core>=1.0.0"]
|
requires = ["poetry-core>=1.0.0"]
|
||||||
|
Reference in New Issue
Block a user