Django: Performing ManytoMany Queries

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=)

0 Comments, 0 trackbacks (Trackback URL)

0 responses to Django: Performing ManytoMany Queries

Leave a Comment
  1. (required)
  2. Ignore this field:
  3. Don't put anything in this field:
    Don't put anything here:
  4. Leave this empty:
    (required)
  5. Your email is not publically displayed.