如何自定义某个search_fields字段的UI组件
lifengmds opened this issue · 3 comments
lifengmds commented
以教程中的示例代码为例,category的筛选需要下拉菜单dropdown list, 但是系统默认为input文本输入。如何重写并自定义该字段、并且不影响其它search_fields字段的自动生成。
from fastapi_amis_admin import admin
from fastapi_amis_admin.models.fields import Field
class Article(SQLModel, table=True):
id: int = Field(default=None, primary_key=True, nullable=False)
title: str = Field(title='ArticleTitle', max_length=200)
description: Optional[str] = Field(default='', title='ArticleDescription', max_length=400)
status: bool = Field(None, title='status')
content: str = Field(title='ArticleContent')
category_id: Optional[int] = Field(default=None, foreign_key="category.id", title='CategoryId')
is_active: bool = False
@site.register_admin
class ArticleAdmin(admin.ModelAdmin):
page_schema = 'article management'
model = Article
# Set the fields to display
list_display = [Article.id, Article.title, Article.description, Article.status, Category.name]
# Set up fuzzy search field
search_fields = [Article.title, Category.name]
# custom base selector
async def get_select(self, request: Request) -> Select:
stmt = await super().get_select(request)
return stmt.outerjoin(Category, Article.category_id == Category.id)
amisadmin commented
继承ModelAdmin重写get_form_item方法
ginea commented
可以给个示例吗?
zinohome commented
这个东西start的文档是够了,如果要搞清楚,按规范的方法来写,确实有很多地方需要自己摸索,没有文档,只能看源码来一点点摸索作者的意图,@amisadmin , 东西不错,但是思路给大家讲清楚也很重要,希望越来越好,如果有能帮忙的也乐意参与。