I have the following model:
class Campaign(models.Model):
some_campaign_field = models.CharField()
class Position(models.Model):
campaign = models.Forei
Thanks to the suggestions in the comments, I ended up with the following working solution:
open_campaigns = list(Campaign.objects.prefetch_related(
Prefetch('position_set',
queryset=Position.objects.all(),
to_attr='cached_positions'),
Prefetch('cached_positions__trade_set',
to_attr='cached_trades'),
).filter(exit_datetime__isnull=True))
Edit: it should be added this import
from django.db.models import Prefetch
Ref. Prefetch docs