mirror of
https://github.com/fastapi-admin/fastapi-admin.git
synced 2025-08-15 11:11:19 +08:00
19 lines
449 B
Python
19 lines
449 B
Python
from typing import Generic
|
|
|
|
from fastapi import HTTPException
|
|
from starlette.status import HTTP_404_NOT_FOUND
|
|
from tortoise.models import MODEL
|
|
|
|
|
|
async def get_object_or_404(model: Generic[MODEL], **kwargs):
|
|
"""
|
|
get_object_or_404
|
|
:param model:
|
|
:param kwargs:
|
|
:return:
|
|
"""
|
|
obj = await model.filter(**kwargs).first() # type:model
|
|
if not obj:
|
|
raise HTTPException(HTTP_404_NOT_FOUND, "Not Found")
|
|
return obj
|