first add
This commit is contained in:
25
backend/app/models/base.py
Normal file
25
backend/app/models/base.py
Normal file
@@ -0,0 +1,25 @@
|
||||
"""基础模型"""
|
||||
from datetime import datetime
|
||||
from sqlmodel import SQLModel, Field
|
||||
from uuid import uuid4
|
||||
|
||||
|
||||
def generate_uuid() -> str:
|
||||
"""生成 UUID"""
|
||||
return str(uuid4())
|
||||
|
||||
|
||||
class TimestampModel(SQLModel):
|
||||
"""时间戳 Mixin"""
|
||||
created_at: datetime = Field(
|
||||
default_factory=datetime.utcnow,
|
||||
nullable=False,
|
||||
sa_column_kwargs={"index": True},
|
||||
)
|
||||
updated_at: datetime = Field(
|
||||
default_factory=datetime.utcnow,
|
||||
nullable=False,
|
||||
sa_column_kwargs={"onupdate": datetime.utcnow},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user