Skip to content

Commit

Permalink
Merge pull request #182 from kingmo888/master
Browse files Browse the repository at this point in the history
更新基础教程部分章节
  • Loading branch information
amisadmin authored Aug 18, 2024
2 parents 325e906 + 00f8a83 commit 90fea56
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion docs/zh/docs/tutorials/basic/Inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MyHomeAdmin(admin.HomeAdmin):
return page
```

## 示例-2(自定义模板管理基类)
## 示例-2.1(自定义模板管理基类)

根目录`templates`文件夹中新建`element.html`,html内容如下:
```html
Expand Down Expand Up @@ -81,6 +81,30 @@ class ElementTemplateAdmin(MyJinja2Admin):
return {'current_time': datetime.datetime.now(), 'title': 'Element Content'}

```
## 示例-2.2(将多个page以tab形式展示)
我们基于示例2.1进行修改,
1、首先将`SimpleTemplateAdmin``ElementTemplateAdmin`的页面注册装饰函数(`@site.register_admin`)注释或删除。
2、我们创建一个Page管理页,然后将上述2个页面注册到`TemplatePageApp`下。
```python
from fastapi_amis_admin import admin, amis
from fastapi_amis_admin.admin import AdminApp
from fastapi_amis_admin.amis import TabsModeEnum


@site.register_admin
class TemplatePageApp(admin.AdminApp):
page_schema = PageSchema(label="TemplatePage", icon="fa fa-link", tabsMode=TabsModeEnum.chrome)

def __init__(self, app: "AdminApp"):
super().__init__(app)
self.register_admin(
SimpleTemplateAdmin,
ElementTemplateAdmin,
)
```
此时,左侧菜单栏将会显示TemplatePageApp的类目,同时TemplatePageApp页面下则显示`SimpleTemplateAdmin``ElementTemplateAdmin`相关tab。


## 示例-3(重用模型管理类)
我们在*模型管理*-示例2的基础上进行改造,将`Article`类新增一行属性`is_active: bool = False # add`,如下:
```python linenums="1" hl_lines="32"
Expand Down
2 changes: 2 additions & 0 deletions docs/zh/docs/tutorials/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pip install fastapi_amis_admin

## 简单示例

后续的*基础教程*部分将围绕一下这两个文件来展开。

1.创建文件**`adminsite.py`**:

```python
Expand Down

0 comments on commit 90fea56

Please sign in to comment.