[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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM