例如:
@app.route('/courselist', methods=['GET', 'POST'])
def courselist():
courses = models.Course.query.all()
return render_template('courselist.html', title = 'Manage courses', courses = courses)
有没有办法按字母顺序排序这个查询?
编辑:这些是我的模型。
class Course(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(40), unique=True)
courseCode = db.Column(db.String(10), unique=True)
duration = db.Column(db.Integer)
maxStudents = db.Column(db.Integer)
startDate = db.Column(db.DateTime)
prerequisites = db.Column(db.String(500))
trainerID = db.Column(db.Integer, db.ForeignKey('trainer.id'))
venueID = db.Column(db.Integer, db.ForeignKey('venue.id'))