SQLAlchemy ordering by count on a many to many relationship
I haven’t used SQLAlchemy much so I figured I’d give it a shot. I didn’t try to use your models, I just wrote some new ones (similar enough though): likes = db.Table(‘likes’, db.Column(‘user_id’, db.Integer, db.ForeignKey(‘user.id’)), db.Column(‘post_id’, db.Integer, db.ForeignKey(‘post.id’)) ) class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20)) def __repr__(self): return “<User(‘%s’)>” % self.username class … Read more