django – ordering queryset by a calculated field

If you would not mind some logic duplicaton, then the following will work:

Foo.objects.extra(select={'d_field': 'A - B'}).extra(order_by=['d_field'])

Leave a Comment