mirror of
https://git.oceanpay.cc/danial/kami_apple_exchage.git
synced 2025-12-18 21:23:49 +00:00
- 新增 CODEBUDDY.md、GEMINI.md、GEMINI_CN.md 等项目文档 - 更新 Dockerfile 和其他配置文件 - 优化部分代码结构,如 orders.py、tasks.py 等 - 新增 .dockerignore 文件
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""
|
|
用户资料相关模型
|
|
"""
|
|
|
|
from typing import TYPE_CHECKING
|
|
from sqlalchemy import String, Index
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from .base import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from .orders import Orders
|
|
|
|
|
|
class UserData(BaseModel):
|
|
"""用户资料数据表"""
|
|
|
|
__tablename__ = "user_data"
|
|
__table_args__ = (
|
|
Index("ix_user_data_email", "email"),
|
|
Index("ix_user_data_phone", "phone"),
|
|
Index("ix_user_data_name", "first_name", "last_name"),
|
|
)
|
|
|
|
first_name: Mapped[str] = mapped_column(String(255), nullable=False, comment="名字")
|
|
last_name: Mapped[str] = mapped_column(String(255), nullable=False, comment="姓氏")
|
|
street_address: Mapped[str] = mapped_column(
|
|
String(500), nullable=False, comment="街道地址"
|
|
)
|
|
city: Mapped[str] = mapped_column(String(255), nullable=False, comment="城市")
|
|
state: Mapped[str] = mapped_column(String(255), nullable=False, comment="州/省")
|
|
zip_code: Mapped[str] = mapped_column(
|
|
String(20), nullable=False, comment="邮政编码"
|
|
)
|
|
email: Mapped[str] = mapped_column(String(255), nullable=False, comment="邮箱地址")
|
|
phone: Mapped[str] = mapped_column(String(50), nullable=False, comment="电话号码")
|
|
|
|
# 关系映射
|
|
orders: Mapped[list["Orders"]] = relationship("Orders", back_populates="user_data")
|
|
|
|
def __repr__(self) -> str:
|
|
return (
|
|
f"<UserData(id={self.id}, name={self.first_name} {self.last_name}, "
|
|
f"email={self.email}, phone={self.phone})>"
|
|
)
|
|
|
|
@property
|
|
def full_name(self) -> str:
|
|
"""获取全名"""
|
|
return f"{self.first_name} {self.last_name}"
|
|
|
|
@property
|
|
def full_address(self) -> str:
|
|
"""获取完整地址"""
|
|
return f"{self.street_address}, {self.city}, {self.state} {self.zip_code}"
|