def save_string(string, context, file_path, location=''): string = u'{}'.format(string) try: string_obj = String.objects.get(original=string) except String.DoesNotExist: string_obj = String(file=file_path, location=location, original=string, context=context) string_obj.save()
class Admin(Base): id = Column(Integer, primary_key=True, index=True) username = Column(String(20), comment="账号") password_hash = Column(String(128), comment="密码") blog_title = Column(String(60), comment="博客标题") blog_sub_title = Column(String(100), comment="博客子标题") name = Column(String(30), comment="作者名称") about = Column(Text, comment="关于")
class Movto(DeclarativeBase): __tablename__ = 'movto' data = Column(Date()) account_debit = Column() person_id = Column(Integer, ForeignKey('person.grid')) person = relationship(Person) doc = Column(String(250), nullable=False) name = Column(String(250), nullable=False) email = Column(String(250), nullable=False)
class User(Base): __tablename__ = 'users' id = Column(SmallInteger, primary_key=True, autoincrement=True) name = Column(String(255)) trades = relationship("Trade", back_populates="user") transactions: [] = relationship("Transaction", back_populates="user") follows: [] = relationship("Follow", back_populates="follower") def __init__(self, name): self.name = name
class Comment(Base): id = Column(Integer, index=True, primary_key=True) author = Column(String(30), comment="昵称") content = Column(Text, comment="评论内容") post_id = Column(Integer, ForeignKey('post.id')) post = relationship('Post', back_populates='comments') replied_id = Column(Integer, ForeignKey('comment.id')) replied = relationship('Comment', back_populates='replies', remote_side=[id]) replies = relationship('Comment', back_populates='replied', cascade='all, delete-orphan')
class Post(Base): id = Column(Integer, index=True, primary_key=True) title = Column(String(100), comment="文章标题") body = Column(Text, comment="文章内容") # 文章状态 status = Column(Integer, default=1, comment="文章状态,1 置顶显示 2正常显示 3 不显示") reading = Column(Integer, default=0, comment="阅读量") category_id = Column(Integer, ForeignKey('category.id')) # category = relationship('Category', back_populates='post') category = relationship('Category', back_populates='posts') # 级联操作 comments = relationship('Comment', back_populates='post', cascade='all')
class Link(Base): id = Column(Integer, primary_key=True) name = Column(String(30)) url = Column(String(255))