Мне нужен определенный тип непрочитанного сообщения и сортировка по времени создания, другие типы следуют за непрочитанным, создают воспоминание времени (сначала я хочу type = 7 и status = 0 и time desc (), затем status = 1 и time desc ()))
class Notifications(BaseModel):
type = db.Column(db.Integer, default=0, index=True)
status = db.Column(db.Boolean, default=False)
create_time = db.Column(db.DateTime)
Notifications.query.filter(Notifications.type.in_([7,3,8])).
order_by(case(((Notifications.type == 7, 1),
(Notifications.status == 0, 2),
(Notifications.status == 1, 3))),
Notifications.create_time.desc()).all()
{
"id": 938,
"status": 1,
"time": "2019-06-24 19:34:01",
"type": 7
},
{
"id": 889,
"status": 0,
"time": "2019-06-19 09:02:42",
"type": 7
},
{
"id": 918,
"status": 0,
"time": "2019-06-20 16:43:43",
"type": 8
},
{
"id": 936,
"status": 0,
"time": "2019-06-20 16:32:02",
"type": 3
}