How to JOIN three tables with Django ORM
queryset = Artist.objects.select_related(
'songs', 'fans'
).filter(songs__title__icontains='love', fans__votes_casted__gte=100)
How to JOIN three tables with Django ORM
queryset = Artist.objects.select_related(
'songs', 'fans'
).filter(songs__title__icontains='love', fans__votes_casted__gte=100)
How to JOIN three tables with Django ORM
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()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us