I am trying to access fields in the admin using list_display. According to the docs: (https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display), ManyToManyFields are not supported. I have gotten around this by creating a custom method like this:
#models.py
class Gig
musician = models.ManyToManyField(Musician)
note = models.CharField(max_length=20)
def __unicode__(self):
return u'%s' % (self.note)
def gig_musicians(self):
return self.musician.all()
#admin.py
class GigAdmin
list_display = ('note', 'gig_musicians')
This gives me the result I am looking for but it is very ugly (this works for generic relations too). The results look like:
[<Musician: Richard Bona>, <Musician: Bobby Mcerrin>]
I think it is because of how I built the method. Do you have any advice for how to make this more elegant i.e. just the names?
I tried other solutions such as, django display content of a manytomanyfield, but i couldn't get it to work for me (it just displayed None)