diff --git a/budget/models.py b/budget/models.py index 0670d6e..3aac120 100644 --- a/budget/models.py +++ b/budget/models.py @@ -37,7 +37,7 @@ class Project(db.Model): # for each person for person in self.members: # get the list of bills he has to pay - bills = Bill.query.filter(Bill.owers.contains(person)) + bills = Bill.query.options(orm.subqueryload(Bill.owers)).filter(Bill.owers.contains(person)) for bill in bills.all(): if person != bill.payer: share = bill.pay_each() * person.weight diff --git a/budget/web.py b/budget/web.py index 63fbe4d..87aef26 100644 --- a/budget/web.py +++ b/budget/web.py @@ -15,6 +15,7 @@ from flask.ext.mail import Mail, Message from flask.ext.babel import get_locale, gettext as _ from smtplib import SMTPRecipientsRefused import werkzeug +from sqlalchemy import orm # local modules from models import db, Project, Person, Bill @@ -277,7 +278,8 @@ def list_bills(): # set the last selected payer as default choice if exists if 'last_selected_payer' in session: bill_form.payer.data = session['last_selected_payer'] - bills = g.project.get_bills() + # Preload the "owers" relationship for all bills + bills = g.project.get_bills().options(orm.subqueryload(Bill.owers)) return render_template("list_bills.html", bills=bills, member_form=MemberForm(g.project),