model
class Maintain(models.Model):
STATUS = (
('NOT_PROCESS', '未处理'),
('MAINTAINED', '已保养'),
('ACCEPTED', '已受理'),
('EXPIRED', '已过期'),
('IGNORED', '已忽略'),
)
status = models.CharField('保养提醒状态', choices=STATUS, max_length=15)
queryset = queryset.extra(select={"sort": '''
CASE status WHEN 'ACCEPTED' THEN 1
WHEN 'MAINTAINED' THEN 2
WHEN 'IGNORED' THEN 3
WHEN 'EXPIRED' THEN 4
ELSE 5
END
'''}).order_by('sort')
按照状态自定义排序,select={"sort": '''1"},相当于在每个对象中添加了新的属性,可以按照这个新属性排序