I've tried using these codes so far to pass to my front end on flask. I am trying to get the max views from a column and I have tried looking up some functions but they gave me errors, like the func.max. I am not too familiar with sqlalchemy. If anyone can also link to more commands or some documentation that explains further functions, right now all I understand is dbname.query.filter_by, order_by, get, and all in order to manipulate rows and columns.
hottest_post = Posts.query.order_by(Posts.article_views.asc()).first()
hottest_post = db.posts.query.order_by(func.max(Posts.article_views)).first()
CodePudding user response:
This should work for you:
from sqlalchemy import func
hottest_post = db.session.query(func.max(Posts.article_views))