📅  最后修改于: 2022-03-11 15:00:36.149000             🧑  作者: Mango
>>> # get all posts written by a user
>>> u = User.query.get(1)
>>> u
>>> posts = u.posts.all()
>>> posts
[]
>>> # same, but with a user that has no posts
>>> u = User.query.get(2)
>>> u
>>> u.posts.all()
[]
>>> # print post author and body for all posts
>>> posts = Post.query.all()
>>> for p in posts:
... print(p.id, p.author.username, p.body)
...
1 john my first post!
# get all users in reverse alphabetical order
>>> User.query.order_by(User.username.desc()).all()
[, ]