Models
Throughout Redbox Pydantic models are used to define the structure of the data that is being passed around. This is done to ensure that the data is in the correct format and to provide a level of type safety when passing between Microservices, Database and the API.
In combination with FastAPI, Pydantic models are used to define the structure of the request and response bodies for the API endpoints. It also generates the OpenAPI documentation for the API.
To save all all these models we created a PersistableModel
class that all models that are saved to the database inherit from. This class adds the following fields to all models:
redbox.models.base.PersistableModel
Bases: BaseModel
Base class for all models that can be persisted to the database.
uuid class-attribute
instance-attribute
uuid = Field(default_factory=uuid4)
created_datetime class-attribute
instance-attribute
created_datetime = Field(default_factory=utcnow)
creator_user_uuid instance-attribute
creator_user_uuid
model_type property
model_type
Return the name of the model class.
RETURNS | DESCRIPTION |
---|---|
str | The name of the model class. TYPE: |