This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Author(db.Model): | |
id = db.Column(db.Integer, primary_key=True) | |
forenames = db.Column(db.String(120), index=True) | |
lastname = db.Column(db.String(120), index=True) | |
associations = db.relationship('ArticleAuthor', backref='author') | |
articles = association_proxy('associations', 'article') | |
#intermediate table used for ordering authors within articles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
start_date = arrow.utcnow().replace(months=-2).datetime | |
end_date = arrow.utcnow().datetime | |
gen_stmt = db.session.query(func.generate_series(start_date, end_date, timedelta(1)).label('day')).subquery() | |
donation_day = func.date_trunc(time_unit, Donation.created).label('day') | |
donation_stmt db.session.query(donation_day, func.sum(Donation.amount).label('amount_raised')).\ | |
filter(created.between(start_date, end_date)).group_by(donation_day).subquery() | |
query = db.session.query(gen_stmt, coalesce(donation_stmt.c.amount_raised, 0)).outerjoin(donation_stmt, gen_stmt.c.day == donation_stmt.c.day) |