I'm trying to convert the following SQL query in to a single Django query in order to minimize number of executed sql queries, however I'm not able to do that except using a for-loop.
I appreciate it if anyone could provide me the intended Django query
SQL Query:
select FUND_ID, REPORT_DATE, PURCHASE_NAV_PER_SHARE
FROM FUNDS_HISTORY
WHERE REPORT_DATE = (
SELECT Max(REPORT_DATE)
FROM FUNDS_HISTORY fund_history
where fund_history.FUND_ID = FUNDS_HISTORY.FUND_ID
)
models:
class Fund(models.Model):
name_en = models.CharField(max_length=256, blank=True, null=True)
class History(models.Model):
fund = models.ForeignKey('funds.Fund', on_delete=models.CASCADE, blank=True, null=True)
purchase_nav_per_share = models.BigIntegerField(blank=True, null=True)
report_date = models.DateField(blank=True, null=True)