我如何在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
答案 0 :(得分:0)
instances = Catalog.objects.extra(
select={'ordering': "apple_id=%s" % self.pk}
).order_by('-ordering', 'pk')