list_display a Many to Many field

2,754 views
Skip to first unread message

Fernando Rodríguez

unread,
Jul 9, 2008, 9:31:51 AM7/9/08
to django users
Hi,

I'm trying to display a many to many field in the admin interface.

This is my model:

class Book(models.Model):
title = models.CharField(maxlength = 100, db_index = True)
authors = models.ManyToManyField(Author)
Publisher = models.ForeignKey(Publisher)
publicationDate = models.DateField()

class Admin:
list_display = ('title', 'Publisher', 'publicationDate',
'authors' )
list_filter = ('Publisher', 'publicationDate')
search_fields = ('title')

def __str__(self):
return self.title

In the authors column, instead of the author's name(s), I get what seems
to be the __str__ of an object:
<django.db.models.fields.related.ManyRelatedManager object at 0x874352c>

How can I get this ManyRelatedManager to display what I want? O:-)

Thanks!


Message has been deleted
Message has been deleted

alex....@gmail.com

unread,
Jul 10, 2008, 9:31:17 AM7/10/08
to Django users
No, authors is the related manager, so it's all method returns a
QuerySet with all the relevant items.

On Jul 10, 8:25 am, Fernando Rodríguez <dja...@easyjob.net> wrote:
> El mié, 09-07-2008 a las 06:40 -0700, urukay escribió:
>
>
>
> > this should work:
>
> > def get_authors(self):
> >     return self.authors.all()
>
> Thanks Radovan. Shouldn't it be self.authors.objects.all()?
Reply all
Reply to author
Forward
0 new messages