add bulk actions support

This commit is contained in:
long2ice
2020-04-11 19:53:41 +08:00
parent eb7b0742d6
commit 51e5f7c043
16 changed files with 158 additions and 60 deletions

View File

@@ -10,6 +10,7 @@ from ..common import handle_m2m_fields_create_or_update
from ..depends import QueryItem, get_query, parse_body, get_model
from ..factory import app
from ..responses import GetManyOut
from ..schemas import BulkIn
from ..shortcuts import get_object_or_404
router = APIRouter()
@@ -73,6 +74,17 @@ async def view(
return resource.dict(by_alias=True, exclude_unset=True)
@router.post(
'/{resource}/bulk/delete'
)
async def bulk_delete(
bulk_in: BulkIn,
model=Depends(get_model)
):
await model.filter(pk__in=bulk_in.pk_list).delete()
return {'success': True}
@router.delete(
'/{resource}/{id}'
)