+ 1

On Django Queryset

CONSIDER THE MODELS BELOW: from django.db import models # Create your models here. class Artists(models.Model): AR_SIZE = ( ("S", "Small"), ("M", "Medium"), ("L", "Large"), ) name = models.CharField(max_length=60) height = models.CharField(max_length=1, choices=AR_SIZE) img = models.ImageField(upload_to="images/") des = models.TextField() def __str__(self): return str(self.id) + str(self.name) class Albums(models.Model): artist = models.ForeignKey(Artists, on_delete=models.CASCADE) title = models.CharField(max_length=90) cover = models.ImageField(upload_to="images/cover/") def __str__(self): return str(self.artist) + " " + str(self.title) class Songs(models.Model): album = models.ForeignKey(Albums, on_delete=models.CASCADE) s_title = models.CharField(max_length=80) audio = models.FileField(default='') runtime = models.CharField(max_length=8) def __str__(self): return str(self.album) + " " + str(self.s_title) SO MY QUESTION IS HOW TO GET THE NAME, ID, OF THE ARTISTS FOR A PARTICULAR SONG? WITHOUT USING RAW SQL THANKING YOU IN ADVANCE.

5th Apr 2020, 5:39 AM
Pukhrambam
Pukhrambam - avatar
3 Answers
+ 1
artist = Songs.objects.filter(album__artist__name="picasso")
11th Apr 2021, 9:48 PM
patilkrunal
patilkrunal - avatar
+ 1
Maybe this way using django orm dunder methods
11th Apr 2021, 9:49 PM
patilkrunal
patilkrunal - avatar
11th Apr 2021, 9:53 PM
patilkrunal
patilkrunal - avatar