|
|||||||
sorting records / сортировка
Время создания: 12.05.2017 16:59
Раздел: Python - Модули - peewee
Запись: xintrea/mytetra_db_mcold/master/base/1494597541sbdjkvt6mh/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
Sorting records To return rows in order, use the order_by() method: >>> for t in Tweet.select().order_by(Tweet.created_date): ... print t.pub_date ...
2010-01-01 00:00:00
2011-06-07 14:08:48
2011-06-07 14:12:57
>>> for t in Tweet.select().order_by(Tweet.created_date.desc()): ... print t.pub_date ...
2011-06-07 14:12:57
2011-06-07 14:08:48
2010-01-01 00:00:00
You can also use + and - prefix operators to indicate ordering: # The following queries are equivalent:
Tweet.select().order_by(Tweet.created_date.desc()) Tweet.select().order_by(-Tweet.created_date) # Note the "-" prefix. # Similarly you can use "+" to indicate ascending order:
User.select().order_by(+User.username) You can also order across joins. Assuming you want to order tweets by the username of the author, then by created_date: >>> qry = Tweet.select().join(User).order_by(User.username, Tweet.created_date.desc()) |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|