- Implemented TableBaseMixin providing generic CRUD methods and automatic timestamp management. - Introduced UUIDTableBaseMixin for models using UUID as primary keys. - Added ListResponse for standardized paginated responses. - Created TimeFilterRequest and PaginationRequest for filtering and pagination parameters. - Enhanced get_with_count method to return both item list and total count. - Included validation for time filter parameters in TimeFilterRequest. - Improved documentation and usage examples throughout the code.
33 lines
815 B
Python
33 lines
815 B
Python
|
||
from typing import TYPE_CHECKING
|
||
from uuid import UUID
|
||
|
||
from sqlmodel import Field, Relationship, Index
|
||
|
||
from .base import SQLModelBase
|
||
from .mixin import TableBaseMixin
|
||
|
||
if TYPE_CHECKING:
|
||
from .object import Object
|
||
|
||
|
||
class SourceLink(SQLModelBase, TableBaseMixin):
|
||
"""链接模型"""
|
||
|
||
__table_args__ = (
|
||
Index("ix_sourcelink_object_name", "object_id", "name"),
|
||
)
|
||
|
||
name: str = Field(max_length=255)
|
||
"""链接名称"""
|
||
|
||
downloads: int = Field(default=0, sa_column_kwargs={"server_default": "0"})
|
||
"""通过此链接的下载次数"""
|
||
|
||
# 外键
|
||
object_id: UUID = Field(foreign_key="object.id", index=True)
|
||
"""关联的对象UUID(必须是文件类型)"""
|
||
|
||
# 关系
|
||
object: "Object" = Relationship(back_populates="source_links")
|
||
"""关联的对象""" |