【发布时间】:2015-02-15 18:26:37
【问题描述】:
这是我拥有的代码,它正在运行(返回所有按难度排序的问题):
def get_noteworthy_problems(self):
ACategory = aliased(Category)
AProblem = aliased(Problem)
all_prob = DBSession.query(AProblem).filter(
AProblem.parent_id == ACategory.id,
ACategory.parent_id == self.id)
noteworthy_problems = \
sorted(all_prob, key=lambda x: x.difficulty(), reverse=True)
return noteworthy_problems
但我认为我必须优化这段代码。
是否有可能更改具有order_by 和我的函数difficulty() 的代码?我的函数返回一个数字。我试过类似的东西:
result = DBSession.query(AProblem).filter(
AProblem.parent_id == ACategory.id,
ACategory.parent_id == self.id).order_by(
AProblem.difficulty().desc())
但我收到错误TypeError: 'NoneType' object is not callable。
【问题讨论】:
标签: python sql sql-server sqlalchemy