Reputation: 1595
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.
Upvotes: 1
Views: 429
Reputation: 19155
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.
Upvotes: 1