update:更新自定义写作风格模块
This commit is contained in:
@@ -5,6 +5,8 @@ from app.models.character import Character
|
||||
from app.models.chapter import Chapter
|
||||
from app.models.generation_history import GenerationHistory
|
||||
from app.models.settings import Settings
|
||||
from app.models.writing_style import WritingStyle
|
||||
from app.models.project_default_style import ProjectDefaultStyle
|
||||
from app.models.relationship import (
|
||||
RelationshipType,
|
||||
CharacterRelationship,
|
||||
@@ -19,6 +21,8 @@ __all__ = [
|
||||
"Chapter",
|
||||
"GenerationHistory",
|
||||
"Settings",
|
||||
"WritingStyle",
|
||||
"ProjectDefaultStyle",
|
||||
"RelationshipType",
|
||||
"CharacterRelationship",
|
||||
"Organization",
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
"""项目默认风格关联表"""
|
||||
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class ProjectDefaultStyle(Base):
|
||||
"""项目默认风格关联表 - 记录每个项目选择的默认风格"""
|
||||
__tablename__ = "project_default_styles"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
project_id = Column(String(36), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False, comment="项目ID")
|
||||
style_id = Column(Integer, ForeignKey("writing_styles.id", ondelete="CASCADE"), nullable=False, comment="风格ID")
|
||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
||||
|
||||
# 确保每个项目只有一个默认风格
|
||||
__table_args__ = (
|
||||
UniqueConstraint('project_id', name='uix_project_default_style'),
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ProjectDefaultStyle(project_id={self.project_id}, style_id={self.style_id})>"
|
||||
@@ -0,0 +1,23 @@
|
||||
"""写作风格数据模型"""
|
||||
from sqlalchemy import Column, String, Text, Boolean, DateTime, ForeignKey, Integer
|
||||
from sqlalchemy.sql import func
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class WritingStyle(Base):
|
||||
"""写作风格表"""
|
||||
__tablename__ = "writing_styles"
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
project_id = Column(String(36), ForeignKey("projects.id", ondelete="CASCADE"), nullable=True, comment="所属项目ID(NULL表示全局预设风格)")
|
||||
name = Column(String(100), nullable=False, comment="风格名称")
|
||||
style_type = Column(String(50), nullable=False, comment="风格类型:preset/custom")
|
||||
preset_id = Column(String(50), comment="预设风格ID:natural/classical/modern等")
|
||||
description = Column(Text, comment="风格描述")
|
||||
prompt_content = Column(Text, nullable=False, comment="风格提示词内容")
|
||||
order_index = Column(Integer, default=0, comment="排序序号")
|
||||
created_at = Column(DateTime, server_default=func.now(), comment="创建时间")
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), comment="更新时间")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<WritingStyle(id={self.id}, name={self.name}, project_id={self.project_id})>"
|
||||
Reference in New Issue
Block a user