May 27th, 2009 posted by Bender Rodríguez
Given the models below:
class Artist(models.Model):
name = models.CharField(max_length=128)
def __unicode__(self):
return u'%s' %(self.name)
class Album(models.Model):
title = models.CharField(max_length=128)
artists = models.ManyToManyField(Artist)
def __unicode__(self):
return u'%s' %(self.title)
class Song(models.Model):
title = models.CharField(max_length=128)
albums = models.ManyToManyField(Album)
def __unicode__(self):
return self.title
Here is how you can get a list of all the songs a particular artist has:
Song.objects.filter(albums__artists=
"I used to think that people who regarded everyone benignly were a mite simple or oblivious or just plain lax -- until I tried it myself. Then I realized that they made it only look easy. Even the Berditchever Rebbe, revered as a man who could strike a rock and bring forth a stream, was continually honing his intentions. "Until I remove the thread of hatred from my heart," he said of his daily meditations, "I am, in my own eyes, as if I did not exist.""
Marc Barasch