update docs

This commit is contained in:
long2ice
2021-05-09 15:11:52 +08:00
parent 3e9c6f636e
commit 4aebeda3e8
9 changed files with 257 additions and 215 deletions

View File

@@ -54,3 +54,11 @@ You can enable site search by add `SearchProvider` to `admin_app.configure(...)`
```python
await admin_app.configure(providers=[SearchProvider()])
```
## Notification
You can use notification by adding `NotificationProvider` to `admin_app.configure(...) implement by websocket.
```python
await admin_app.configure(providers=[NotificationProvider()])
```

View File

@@ -0,0 +1,47 @@
# Notification (💗 Pro only)
`FastAPI-Admin` provide a notification center implement by websocket.
![](https://github.com/fastapi-admin/fastapi-admin/blob/dev/images/notification.png?raw=true)
## Usage
You should add it to providers to enable it.
```python
from fastapi import FastAPI
from fastapi_admin.app import app as admin_app
from fastapi_admin.providers.notification import NotificationProvider
app = FastAPI()
provider = NotificationProvider()
@app.on_event("startup")
async def startup():
await admin_app.configure(
providers=[provider]
)
```
There are two ways to send notifications.
One is call `await provider.broadcast()` directly.
```python
data = {
"title": "test",
"content": "//avatars.githubusercontent.com/u/13377178?v=4",
"image": "https://avatars.githubusercontent.com/u/13377178?v=4"
}
await provider.broadcast(data)
```
If you want to send notifications out of application, another way is use http api.
```python
import requests
requests.post('http://localhost:8000/admin/notification', json=data)
```

View File

@@ -52,6 +52,7 @@ nav:
- reference/admin_log.md
- reference/global_search.md
- reference/errors.md
- reference/notification.md
- Customization:
- custom/page.md
- custom/overwrite.md