Hi all,
I'm trying to show the content of a manytomanyfield in the admin interface. I have the following code:
class Member(models.Model):
group = models.ManyToManyField('Group')
def group_gp_name(self):
return self.group.gp_name
def __unicode__(self):
return u'%s' % (self.id)
class Group(models.Model):
gp_name = models.TextField(verbose_name=u'Group Name')
def __unicode__(self):
return u'%s - %s' % (self.id, self.gp_name)
In the admin i have something like this:
class MemberAdmin(admin.ModelAdmin):
list_display = ('group_gp_name')
This method worked for showing Foreignkey data. Obviously this doesn't work with ManytoManyFields.. so my question is, how can i show my group names in my admin page under Member. So when i click in the admin on 'Member' i want to see immediately the content of the Group names coupled by the manytomany relation?
UPDATE!!! - I don't want to show them in my change page is just want to see the result in the table. I've found this and it's almost what i want:
def get_sol(self):
return self.group.all()
This works but the view is little bit weird, it shows something like this:
<Group: Administrators >]
The problem is, i don't want to see those '[Group :' and '>]', so how do i get rid of these?
UPDATE2!!!
It helped me out, but what if for example this happens? I've got a 3rd table called Test like this:
class Test(models.Model):
member = models.ForeignKey('Member')
Now i wanna show in the admin view 'Test' the group name from the table 'Group', how is that possible?
Any help is appreciated.
Regards, T