I have basic models for User and Post. In my User model, I have
posts = db.relationship('Post', backref='user', lazy='dynamic')
However, when I do something like
return render_template('user.html', users=users)
I want to do something like
{% for user in users %} <tr> <td>{{ user.id }}</td> <td>{{ user.posts|length }}</td> </tr> {% endfor %}
Unfortunately this does not work. Messages are a request, not a b / c lazy='dynamic' object. I can do the above if I change lazy='joined' , but then it will download all messages for users at any time when I request a user.
I tried adding .options(joinedload('posts')) to my request, but he said that
InvalidRequestError: "User.posts" does not support a population of objects. You cannot use a downloadable download.
Any help is appreciated.
python flask jinja2 flask-sqlalchemy sqlalchemy
Patrick yan
source share