views:

216

answers:

1

We have three models, Artist:

class Artist(models.Model):
    family_name = models.CharField(max_length=50)
    given_name = models.CharField(max_length=50)

Group:

class Group(models.Model):
    name = models.CharField(max_length=50)
    members = models.ManyToManyField(Artist, through='Membership')

and Membership:

class Membership(models.Model)
    artist = models.ForeignKey(Artist)
    group = models.ForeignKey(Group)
    joined = models.DateField()

Membership is an intermediary model connecting Artist and Group with some extra data (date joined, etc.) I was asked to see if one could filter artists by what group they're in but I can't figure out how to do that.

+1  A: 

If you define a m2m between artist and group using through=Membership, you can set up a filter directly on group without going through membership. Can't remember if the syntax is

list_filter = ['group']

or

list_filter = ['group_set']

or something similar.

jcdyer
Thanks for your answer! I tried both of those and got errors saying that the field `group` or `group_set` didn't exist.
Bryan Veloso
So - is the answer marked as 'accepted' incorrect?
andybak