94 lines
2.4 KiB
Python
Raw Permalink Normal View History

2025-02-13 02:27:44 +08:00
# _*_ coding : UTF-8 _*_
# @Time : 2025/01/19 00:46
# @UpdateTime : 2025/01/19 00:46
# @Author : sonder
# @File : file.py
# @Software : PyCharm
# @Comment : 本程序
from tortoise import fields
from models.common import BaseModel
class File(BaseModel):
"""
文件表模型
"""
name = fields.CharField(
max_length=255,
description="文件名",
source_field="name" # 映射到数据库字段 name
)
"""
文件名
- 包括文件扩展名
- 最大长度为 255 个字符
- 映射到数据库字段 name
"""
size = fields.BigIntField(
description="文件大小(字节)",
source_field="size" # 映射到数据库字段 size
)
"""
文件大小
- 单位字节
- 映射到数据库字段 size
"""
file_type = fields.CharField(
max_length=100,
description="文件类型",
source_field="file_type" # 映射到数据库字段 file_type
)
"""
文件类型
- 例如image/pngapplication/pdf
- 最大长度为 100 个字符
- 映射到数据库字段 file_type
"""
absolute_path = fields.CharField(
max_length=512,
description="绝对路径",
source_field="absolute_path" # 映射到数据库字段 absolute_path
)
"""
绝对路径
- 文件在服务器上的绝对路径
- 最大长度为 512 个字符
- 映射到数据库字段 absolute_path
"""
relative_path = fields.CharField(
max_length=512,
description="相对路径",
source_field="relative_path" # 映射到数据库字段 relative_path
)
"""
相对路径
- 文件相对于某个根目录的相对路径
- 最大长度为 512 个字符
- 映射到数据库字段 relative_path
"""
uploader = fields.ForeignKeyField(
"models.User",
related_name="uploaded_files",
null=True, # 允许为空
description="上传人员",
source_field="uploader_id" # 映射到数据库字段 uploader_id
)
"""
上传人员
- 外键关联到 User
- 允许为空例如系统自动上传的文件
- 映射到数据库字段 uploader_id
"""
class Meta:
table = "file" # 数据库表名
table_description = "文件表" # 表描述
ordering = ["-create_time"] # 默认按创建时间倒序排序