[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