35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
|
|
"""
|
||
|
|
User 数据模型
|
||
|
|
"""
|
||
|
|
from tortoise.models import Model
|
||
|
|
from tortoise import fields
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
class User(Model):
|
||
|
|
"""用户模型"""
|
||
|
|
|
||
|
|
id = fields.IntField(pk=True, description="主键ID")
|
||
|
|
username = fields.CharField(max_length=50, unique=True, description="用户名")
|
||
|
|
email = fields.CharField(max_length=100, unique=True, description="邮箱")
|
||
|
|
hashed_password = fields.CharField(max_length=128, description="哈希密码")
|
||
|
|
is_active = fields.BooleanField(default=True, description="是否激活")
|
||
|
|
is_superuser = fields.BooleanField(default=False, description="是否超级用户")
|
||
|
|
|
||
|
|
# 时间戳
|
||
|
|
created_at = fields.DatetimeField(auto_now_add=True, description="创建时间")
|
||
|
|
updated_at = fields.DatetimeField(auto_now=True, description="更新时间")
|
||
|
|
|
||
|
|
# 反向关系
|
||
|
|
items: fields.ReverseRelation["Item"]
|
||
|
|
|
||
|
|
def __str__(self):
|
||
|
|
return f"User(id={self.id}, username={self.username})"
|
||
|
|
|
||
|
|
class Meta:
|
||
|
|
table = "users"
|
||
|
|
table_description = "用户表"
|
||
|
|
ordering = ["-created_at"]
|
||
|
|
|
||
|
|
class PydanticMeta:
|
||
|
|
# Pydantic 模型配置
|
||
|
|
exclude = ["hashed_password"]
|