1from django.db import models
2
3class Artist(models.Model):
4 name = models.CharField(max_length=60)
5 year_established = models.SmallIntegerField()
6 votes = models.IntegerField(blank=True, null=True)
7
8
9class Song(models.Model):
10 artist = models.ForeignKey(Artist, related_name='songs')
11 title = models.CharField(max_length=5)
12 votes = models.IntegerField()
13
14
15class Fan(models.Model):
16 artist = models.ForeignKey(Artist, related_name='fans')
17 name = models.CharField(max_length=5)
18 votes_casted = models.IntegerField()
19
1queryset = Artist.objects.select_related(
2 'songs', 'fans'
3).filter(songs__title__icontains='love', fans__votes_casted__gte=100)
4