mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-13 04:39:41 +00:00
refactor: 重构文件导入组件为通用组件 fix: 修复导出文件名统一问题 docs: 更新README添加二次开发教程 style: 统一系统管理页面的日期选择器实现 chore: 更新数据库迁移脚本和初始化数据 perf: 优化前端页面日期范围选择交互 test: 添加演示模块相关测试文件 build: 更新依赖项配置 ci: 调整CI/CD脚本配置
41 lines
1.5 KiB
Python
41 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Dict, List, Optional, Sequence
|
|
|
|
from app.core.base_crud import CRUDBase
|
|
from app.api.v1.models.demo.example_model import ExampleModel
|
|
from app.api.v1.schemas.demo.example_schema import ExampleCreateSchema, ExampleUpdateSchema
|
|
from app.api.v1.schemas.system.auth_schema import AuthSchema
|
|
|
|
|
|
class ExampleCRUD(CRUDBase[ExampleModel, ExampleCreateSchema, ExampleUpdateSchema]):
|
|
"""示例数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""初始化CRUD"""
|
|
self.auth = auth
|
|
super().__init__(model=ExampleModel, auth=auth)
|
|
|
|
async def get_by_id_crud(self, id: int) -> Optional[ExampleModel]:
|
|
"""详情"""
|
|
return await self.get(id=id)
|
|
|
|
async def get_list_crud(self, search: Dict = None, order_by: List[Dict[str, str]] = None) -> Sequence[ExampleModel]:
|
|
"""列表查询"""
|
|
return await self.list(search=search, order_by=order_by)
|
|
|
|
async def create_crud(self, data: ExampleCreateSchema) -> Optional[ExampleModel]:
|
|
"""创建"""
|
|
return await self.create(data=data)
|
|
|
|
async def update_crud(self, id: int, data: ExampleUpdateSchema) -> Optional[ExampleModel]:
|
|
"""更新"""
|
|
return await self.update(id=id, data=data)
|
|
|
|
async def delete_crud(self, ids: List[int]) -> None:
|
|
"""删除"""
|
|
return await self.delete(ids=ids)
|
|
|
|
async def set_available_crud(self, ids: List[int], status: bool) -> None:
|
|
"""批量设置可用状态"""
|
|
return await self.set(ids=ids, status=status) |