Django额外的特殊订单

时间:2014-10-28 01:46:32

标签: mysql django

我如何在django中执行以下ORDER BY

instances = Catalog.objects.extra(order_by=('apple_id=%s DESC' %self.pk, 'apple_id'))

结果应为:

SELECT * FROM catalog ORDER BY (apple_id=%s DESC), apple_id

1 个答案:

答案 0 :(得分:0)

instances = Catalog.objects.extra(
               select={'ordering': "apple_id=%s" % self.pk}
             ).order_by('-ordering', 'pk')