In the Chapter 4 module, the function:
def sidebar_data():
recent = Post.query.order_by(Post.publish_date.desc()).limit(5).all()
top_tags = db.session.query(
Tag, func.count(tags.c.post_id).label('total')
).join(tags).group_by(Tag).order_by('total DESC').limit(5).all()
errors. You need to include sql along with func in the sqlalchemy import and then modify the join to be:
join(tags).group_by(Tag).order_by(sql.text('total DESC')).limit(5).all()
In the Chapter 4 module, the function: def sidebar_data(): recent = Post.query.order_by(Post.publish_date.desc()).limit(5).all() top_tags = db.session.query( Tag, func.count(tags.c.post_id).label('total') ).join(tags).group_by(Tag).order_by('total DESC').limit(5).all() errors. You need to include sql along with func in the sqlalchemy import and then modify the join to be: join(tags).group_by(Tag).order_by(sql.text('total DESC')).limit(5).all()