CRUD base
base is a module with generic base classes for views.
FastAPIView
Abstract base of all views in that library.
Static attributes:
MODEL: pw.Model- Peewee model for a view_RESPONSE_MODEL: Optional[pd.BaseModel]- Pydantic model for a responseURL: str- Endpoint URLMETHOD: str- Endpoint methodSTATUS_CODE: int- Default 200. Status code for a successful response
Methods:
__call__- abstract method, must be implemented. Main place to put execution logic for a view_get_query- Default: all model instances (self.MODEL.select()). Method to retrieve query. Useful to filter available objects.@property response_model- Property to retrieve Pydantic model for a response._get_api_route_params- Method to retrieve FastAPI route params.add_to_app(app: Union[FastAPI, APIRouter])- Method to add endpoint to application.make_model_view(model: pw.Model)- Class method to create new view for amodelwithout explicitly defining a class.
BaseReadFastAPIView
Abstract base for "read" action views. Inherits FastAPIView.
Methods:
@property response_model- If_RESPONSE_MODELis not specified will make aPwPdModelfor a specifiedMODEL._get_instance(pk: Any)- Method to retrieve instance from query by it's primary key.
BaseWriteFastAPIView
Abstract base for "write" action views. Inherits BaseReadFastAPIView.
Static attributes:
_SERIALIZER: Optional[pd.BaseModel]- Pydantic model for a request body serialization.
Attributes:
_obj_data- Instance of pydantic model (fromserializerproperty) with data from request body.
Methods:
@property serializer- If_SERIALIZERis not specified will make aPwPdWriteModelfor a specifiedMODEL.create- Method for create action. Will create an instance ofMODELin database with data from_obj_dataattribute.update(pk: Any, partial: bool = False)- Method for update action. Will create an update values ofMODELin database by it's primary key with data from_obj_dataattribute. IfpartialisTruewill only use fields that were specified in the request._get_api_route_params- Extends default parameters with dependency to set_obj_dataattribute.
BaseDeleteFastAPIView
Abstract base for "delete" action views. Inherits BaseReadFastAPIView.
Static attributes:
STATUS_CODE = 204-STATUS_CODEset to 204 No Content. Since by default no content will be returned in response.
Methods:
@property response_model- Returns None, since no content in response will be returned.__calll__(pk: Any)- Callsdeletemothod.delete(pk: Any)- Deletes aMODELinstance by it's primary key. Utilizes_get_instancefromBaseReadFastAPIViewto retrieve an instance._get_api_route_params- Removesresponse_modelfrom default parameters. And setsresponse_classtostarlette.responses.Responsefor empty response.