Mysql
 sql >> Database >  >> RDS >> Mysql

sqlalchemy + flask , ricevendo tutti i post di giorno

Non lo farei in una query, ma creerei piuttosto il raggruppamento desiderato sul lato Python:

# get desired posts (add your filters etc)
posts = session.query(Post).order_by(Post.time)

# create a dictionary, where key is the date(-only), and values are the posts of that day
from collections import defaultdict
grouped = defaultdict(list)
for post in posts:
    dat = post.time.date()
    grouped[dat].append(post)

# iterate over new grouped structure
for dat, posts in sorted(grouped.items()):
    print dat
    for post in posts:
        print '  ', post