""" 「友情链接」管理。 - 后台:列表 + 新增 / 编辑 / 删除 / 启用 / 禁用(与 Nav 一致接口风格) - 前台:公开只读 字段: - title : 友链名称 - url : 友链 URL - logo : 站点头像 / favicon(可空,自动用 url 的 favicon) - description : 简介 - category : 友链分组(默认「推荐友链」) - sort : 同分类下排序 - enable : 1 启用,0 禁用 - is_external: 1 新窗口打开 / 0 当前窗口 """ import datetime from applications.extensions import db class Friend(db.Model): __tablename__ = 'site_friend' id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='友情链接ID') title = db.Column(db.String(100), nullable=False, comment='名称') url = db.Column(db.String(255), nullable=False, comment='链接') logo = db.Column(db.String(255), default='', comment='Logo / favicon') description = db.Column(db.String(255), default='', comment='简介') category = db.Column(db.String(50), default='推荐友链', comment='分组', index=True) sort = db.Column(db.Integer, default=0, comment='排序') enable = db.Column(db.Integer, default=1, comment='状态(1启用,0关闭)') is_external = db.Column(db.Integer, default=1, comment='是否外链') create_by = db.Column(db.String(50), default='admin', comment='创建者') create_at = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间') update_at = db.Column( db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间', ) def to_dict(self): return { 'id': self.id, 'title': self.title, 'url': self.url, 'logo': self.logo or '', 'description': self.description or '', 'category': self.category or '推荐友链', 'sort': self.sort or 0, 'enable': self.enable, 'is_external': self.is_external, 'create_by': self.create_by, 'create_at': self.create_at.strftime('%Y-%m-%d %H:%M:%S') if self.create_at else '', 'update_at': self.update_at.strftime('%Y-%m-%d %H:%M:%S') if self.update_at else '', }