FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.
class UserAdmin(admin.ModelAdmin):
group_schema = None
page_schema = PageSchema(label="用户", icon="fa fa-folder")
model = User
search_fields = [User.username]
Error
fastapi.exceptions.RequestValidationError: 1 validation error for Request
body -> username
string does not match regex "^[0-9A-Za-z]{5,30}$" (type=value_error.str.regex; pattern=^[0-9A-Za-z]{5,30}$)
当我删掉regex或者search_fields后恢复正常
目测是获取列表的请求中对字段进行了验证
Full Code
```python
from fastapi import FastAPI
from fastapi_amis_admin import admin
from fastapi_amis_admin.admin import AdminApp
from fastapi_amis_admin.admin.settings import Settings
from fastapi_amis_admin.admin.site import AdminSite
from fastapi_amis_admin.amis import PageSchema
from sqlmodel import Field, SQLModel, create_engine
engine = create_engine(url="sqlite:///amisadmin.db", echo=False)
class User(SQLModel, table=True):
id: int = Field(primary_key=True)
username: str = Field(max_length=32, index=True, unique=True,
regex='^[0-9A-Za-z]{5,30}$')
password: bytes = Field(default=None)
salt: bytes = Field(default=None)
def create_db_table():
SQLModel.metadata.create_all(engine)
create_db_table()
# Create FastAPI application
app = FastAPI()
# Create AdminSite instance
site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db', root_path='/'))
@site.register_admin
class AuthApp(admin.AdminApp):
page_schema = PageSchema(label="用户管理", icon="fa fa-users")
router_prefix = "/eimusic_auth"
def __init__(self, app: "AdminApp"):
super().__init__(app)
self.register_admin(UserAdmin)
class UserAdmin(admin.ModelAdmin):
group_schema = None
page_schema = PageSchema(label="用户", icon="fa fa-folder")
model = User
search_fields = [User.username]
# Mount the background management system
site.mount_app(app)
if __name__ == '__main__':
import uvicorn
uvicorn.run(app)
```
Model
ModelAdmin
Error
当我删掉regex或者search_fields后恢复正常 目测是获取列表的请求中对字段进行了验证
Full Code
```python from fastapi import FastAPI from fastapi_amis_admin import admin from fastapi_amis_admin.admin import AdminApp from fastapi_amis_admin.admin.settings import Settings from fastapi_amis_admin.admin.site import AdminSite from fastapi_amis_admin.amis import PageSchema from sqlmodel import Field, SQLModel, create_engine engine = create_engine(url="sqlite:///amisadmin.db", echo=False) class User(SQLModel, table=True): id: int = Field(primary_key=True) username: str = Field(max_length=32, index=True, unique=True, regex='^[0-9A-Za-z]{5,30}$') password: bytes = Field(default=None) salt: bytes = Field(default=None) def create_db_table(): SQLModel.metadata.create_all(engine) create_db_table() # Create FastAPI application app = FastAPI() # Create AdminSite instance site = AdminSite(settings=Settings(database_url_async='sqlite+aiosqlite:///amisadmin.db', root_path='/')) @site.register_admin class AuthApp(admin.AdminApp): page_schema = PageSchema(label="用户管理", icon="fa fa-users") router_prefix = "/eimusic_auth" def __init__(self, app: "AdminApp"): super().__init__(app) self.register_admin(UserAdmin) class UserAdmin(admin.ModelAdmin): group_schema = None page_schema = PageSchema(label="用户", icon="fa fa-folder") model = User search_fields = [User.username] # Mount the background management system site.mount_app(app) if __name__ == '__main__': import uvicorn uvicorn.run(app) ```