baodan/api/insurance/models/poster_template_model.py

35 lines
1.7 KiB
Python
Raw Normal View History

2026-07-23 15:04:16 +08:00
"""海报模板模型AI 生图方案)。"""
from sqlalchemy import Column, String, Text, SmallInteger, BigInteger, TIMESTAMP, func
from insurance.db.compat import db
class PosterTemplate(db.Model):
"""海报模板表AI 生图方案)。"""
__tablename__ = "poster_templates"
id = Column(BigInteger, primary_key=True, autoincrement=True)
name = Column(String(100), nullable=False, comment="模板名称")
scenario_tag = Column(String(50), nullable=True, comment="场景标签")
style_description = Column(Text, nullable=False, comment="AI 生图风格描述 prompt 片段")
color_scheme = Column(Text, nullable=True, comment="配色方案 JSON")
reference_image = Column(String(500), nullable=True, comment="参考图地址")
preview_image = Column(String(500), nullable=True, comment="预览图地址")
status = Column(SmallInteger, default=1, comment="1=启用, 0=停用")
created_at = Column(TIMESTAMP, server_default=func.now())
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
def to_dict(self):
import json
return {
"id": self.id,
"name": self.name,
"scenarioTag": self.scenario_tag,
"styleDescription": self.style_description,
"colorScheme": json.loads(self.color_scheme) if self.color_scheme else None,
"referenceImage": self.reference_image,
"previewImage": self.preview_image,
"status": self.status,
"createdAt": self.created_at.isoformat() if self.created_at else None,
"updatedAt": self.updated_at.isoformat() if self.updated_at else None,
}