21 lines
860 B
Python
21 lines
860 B
Python
from sqlalchemy import Column, Integer, String, DateTime
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
from app.db.database import Base
|
|
|
|
class User(Base):
|
|
"""用户数据模型"""
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True, index=True)
|
|
openid = Column(String(50), unique=True, index=True)
|
|
unionid = Column(String(50), nullable=True, index=True)
|
|
avatar = Column(String(255), nullable=True, comment="头像")
|
|
nickname = Column(String(50), nullable=True, comment="昵称")
|
|
create_time = Column(DateTime, default=func.now(), comment="创建时间")
|
|
|
|
# 关系
|
|
person_images = relationship("PersonImage", back_populates="user", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<User(id={self.id}, nickname={self.nickname})>" |