queryset = Artist.objects.select_related(
'songs', 'fans'
).filter(songs__title__icontains='love', fans__votes_casted__gte=100)
from django.db import models
class Artist(models.Model):
name = models.CharField(max_length=60)
year_established = models.SmallIntegerField()
votes = models.IntegerField(blank=True, null=True)
class Song(models.Model):
artist = models.ForeignKey(Artist, related_name='songs')
title = models.CharField(max_length=5)
votes = models.IntegerField()
class Fan(models.Model):
artist = models.ForeignKey(Artist, related_name='fans')
name = models.CharField(max_length=5)
votes_casted = models.IntegerField()