# fastapi-admin
### 项目默认会安装
- fastapi_pagination
- fastapi
- tortoise-orm
### 目前只支持pydantic-v2
## 简单示例
> main.py
```python
from fastapi import FastAPI,Depends
from tortoise.contrib.fastapi import register_tortoise
from uvicorn import run
from models import User
from fastapi_tortoise_crud.crud import ModelCrud
user = ModelCrud(User,
schema_filters=User.schema_filters(include=('username',)),
# 除了read接口,其他接口都需要登录
# dependencies=[Depends(get_current_user)],
# depends_read=False
)
app = FastAPI()
app.include_router(user, prefix='/user', tags=['用户管理'])
@app.get("/")
async def root():
return {"message": "Hello World"}
register_tortoise(
app,
db_url="sqlite://:memory:",
modules={"models": ["models"]},
generate_schemas=True,
add_exception_handlers=True,
)
if __name__ == '__main__':
run("main:app", port=2103, reload=True)
```
> models.py
```python
from fastapi_tortoise_crud.model import BaseModel
from tortoise import fields
class User(BaseModel):
username = fields.CharField(64)
password = fields.CharField(32)
nickname = fields.CharField(32, null=True, default='游客')
```
### 路由
![img.png](img.png)
Raw data
{
"_id": null,
"home_page": null,
"name": "fastapi-tortoise-crud",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "Fastapi-admin, Tortoise-orm, Crud",
"author": null,
"author_email": "moxiaoying <768091671@qq.com>",
"download_url": "https://files.pythonhosted.org/packages/30/e2/aeaab063b23632f48f8c79ec88ab958f4be1c7c4721b441a2f0fbf7bb4a0/fastapi_tortoise_crud-0.2.7.tar.gz",
"platform": null,
"description": "# fastapi-admin\n\n### \u9879\u76ee\u9ed8\u8ba4\u4f1a\u5b89\u88c5\n\n- fastapi_pagination\n- fastapi\n- tortoise-orm\n\n### \u76ee\u524d\u53ea\u652f\u6301pydantic-v2\n\n## \u7b80\u5355\u793a\u4f8b\n\n> main.py\n\n```python\nfrom fastapi import FastAPI,Depends\nfrom tortoise.contrib.fastapi import register_tortoise\nfrom uvicorn import run\nfrom models import User\nfrom fastapi_tortoise_crud.crud import ModelCrud\n\nuser = ModelCrud(User,\n schema_filters=User.schema_filters(include=('username',)),\n # \u9664\u4e86read\u63a5\u53e3\uff0c\u5176\u4ed6\u63a5\u53e3\u90fd\u9700\u8981\u767b\u5f55\n # dependencies=[Depends(get_current_user)],\n # depends_read=False\n )\napp = FastAPI()\n\napp.include_router(user, prefix='/user', tags=['\u7528\u6237\u7ba1\u7406'])\n\n\n@app.get(\"/\")\nasync def root():\n return {\"message\": \"Hello World\"}\n\n\nregister_tortoise(\n app,\n db_url=\"sqlite://:memory:\",\n modules={\"models\": [\"models\"]},\n generate_schemas=True,\n add_exception_handlers=True,\n)\n\nif __name__ == '__main__':\n run(\"main:app\", port=2103, reload=True)\n```\n\n> models.py\n\n```python\nfrom fastapi_tortoise_crud.model import BaseModel\nfrom tortoise import fields\n\n\nclass User(BaseModel):\n username = fields.CharField(64)\n password = fields.CharField(32)\n nickname = fields.CharField(32, null=True, default='\u6e38\u5ba2')\n\n```\n\n### \u8def\u7531\n![img.png](img.png)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "fastpi\u7b80\u5355crud",
"version": "0.2.7",
"project_urls": null,
"split_keywords": [
"fastapi-admin",
" tortoise-orm",
" crud"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bb68106db30f64750e31893bef52b17fc21cfcdf6ed942db685fcd4e234d0049",
"md5": "dc243fa87d92379c6465140a7d296dc3",
"sha256": "eedf972b84eacc2652ceaadb2ba08759f4b92f90694326265b74dada4ef7f1a6"
},
"downloads": -1,
"filename": "fastapi_tortoise_crud-0.2.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc243fa87d92379c6465140a7d296dc3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 11415,
"upload_time": "2024-08-21T12:39:35",
"upload_time_iso_8601": "2024-08-21T12:39:35.794059Z",
"url": "https://files.pythonhosted.org/packages/bb/68/106db30f64750e31893bef52b17fc21cfcdf6ed942db685fcd4e234d0049/fastapi_tortoise_crud-0.2.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "30e2aeaab063b23632f48f8c79ec88ab958f4be1c7c4721b441a2f0fbf7bb4a0",
"md5": "4570336df692a8f6961447f8e5ece6ce",
"sha256": "2bfb584614a4610f698f6c979bb66cf5a7cfede4c5477523a198ae8d25ee2bb6"
},
"downloads": -1,
"filename": "fastapi_tortoise_crud-0.2.7.tar.gz",
"has_sig": false,
"md5_digest": "4570336df692a8f6961447f8e5ece6ce",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 10599,
"upload_time": "2024-08-21T12:39:38",
"upload_time_iso_8601": "2024-08-21T12:39:38.120681Z",
"url": "https://files.pythonhosted.org/packages/30/e2/aeaab063b23632f48f8c79ec88ab958f4be1c7c4721b441a2f0fbf7bb4a0/fastapi_tortoise_crud-0.2.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-21 12:39:38",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "fastapi-tortoise-crud"
}