MariaDB[blog]>descposts;+---------------+-------------+------+-----+---------+----------------+|Field|Type|Null|Key|Default|Extra|+---------------+-------------+------+-----+---------+----------------+|id|int(11)|NO|PRI|NULL|auto_increment||title|varchar(64)|YES|UNI|NULL|||body|text|YES||NULL|||body_html|text|YES||NULL|||timestamp|datetime|YES||NULL|||author_id|int(11)|YES|MUL|NULL|||comment_count|int(11)|YES||NULL||+---------------+-------------+------+-----+---------+----------------+7rowsinset(0.00sec)MariaDB[blog]>desctalks;+---------------+-------------+------+-----+---------+----------------+|Field|Type|Null|Key|Default|Extra|+---------------+-------------+------+-----+---------+----------------+|id|int(11)|NO|PRI|NULL|auto_increment||title|varchar(64)|YES|UNI|NULL|||body|text|YES||NULL|||body_html|text|YES||NULL|||timestamp|datetime|YES||NULL|||author_id|int(11)|YES|MUL|NULL|||comment_count|int(11)|YES||NULL||+---------------+-------------+------+-----+---------+----------------+这有两张结构相同的表。我向通过时间做聚合排序。sql语句如下:select*from(select*frompostsunionselect*fromtalks)asa_borderbytimestamp;python代码:classPost(db.Model):__tablename__='posts'id=db.Column(db.Integer,primary_key=True)title=db.Column(db.String(64),unique=True,index=True)body=db.Column(db.Text)body_html=db.Column(db.Text)timestamp=db.Column(db.DateTime,default=datetime.utcnow)tags=db.relationship('Tag',secondary=pwt,backref=db.backref('posts',lazy='dynamic'),lazy='dynamic')author_id=db.Column(db.Integer,db.ForeignKey('users.id'))comments=db.relationship('Comment',backref='post',lazy='dynamic')classTalk(db.Model):__tablename__='talks'id=db.Column(db.Integer,primary_key=True)title=db.Column(db.String(64),unique=True,index=True)body=db.Column(db.Text)body_html=db.Column(db.Text)timestamp=db.Column(db.DateTime,default=datetime.utcnow)tags=db.relationship('Tag',secondary=twt,backref=db.backref('talks',lazy='dynamic'),lazy='dynamic')author_id=db.Column(db.Integer,db.ForeignKey('users.id'))comments=db.relationship('Comment',backref='talk',lazy='dynamic')请问转化成sqlalchemy怎么写?
添加回答
举报
0/150
提交
取消