[flask-sqlalchemy]倒序查询结果

按创建时间倒序查询测试用例

>>> a= TestCase.query.order_by(TestCase.create_time.desc()).first()
>>> a
<TestCase.首页查看全部xxx>

注意 order_by()括号中的写法:

直接写creater_time.desc()会报AttributeError

>>> a= TestCase.query.order_by(id.desc()).first()
Traceback (most recent call last):
  File "/usr/lib/python3.6/code.py", line 91, in runcode
    exec(code, self.locals)
  File "<console>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute 'desc'

正确的写法是TestCase.creater_time.desc()

posted @ 2019-11-19 09:29  wangju003  阅读(3675)  评论(0编辑  收藏  举报