我要使用此表通过flask_sqlalchemy汇总烧瓶中的数据:
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
pages= relationship('Page', backref=backref("user"))
tags = db.Table('tags',
db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True),
db.Column('page_id', db.Integer, db.ForeignKey('page.id'), primary_key=True)
)
class Page(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100))
tags = db.relationship('Tag', secondary=tags, lazy='subquery',
backref=db.backref('pages', lazy=True))
class Tag(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100))
结果必须是这样的:
| user | count of pages | count of tags |
|------|----------------|---------------|
| | | |