Решение подсказал
Вадим Шаталов. Сылка:
https://docs.djangoproject.com/en/dev/ref/models/e...
В моем случае вот что получилось:
class Item(models.Model):
name = models.CharField(max_length=255)
price = models.DecimalField(max_digits=16, decimal_places=2)
class ConvertedPrice(models.Model):
item = models.ForeignKey(Item, on_delete=models.CASCADE)
currency = models.CharField(max_length=3)
value = models.DecimalField(max_digits=16, decimal_places=2)
ordered_items = Item.objects.annotate(converted=Subquery(
ConvertedPrice.objects.filter(item=OuterRef('id'), currency='USD').values('value')
)).order_by('converted')
И на выходе вот такой SQL:
SELECT
"app_item"."id",
"app_item"."name",
"app_item"."price",
(
SELECT U0."value"
FROM "app_convertedprice" U0
WHERE (U0."currency" = USD AND U0."item_id" = ("app_item"."id"))
) AS "converted"
FROM "app_item"
ORDER BY "converted" ASC;