On Wed, Jan 28, 2009 at 6:19 AM, João Olavo Baião de Vasconcelos <
[email protected]> wrote:
> Hi all,
>
> I'd like to search in a m2mfield using the search_fields trick in admin
> interface (django 1.0.2).
>
> A simple example of models:
> """
> class Book(models.Model):
> title = models.CharField(...)
> authors = models.ManyToManyField('author')
>
> class Author(models.Model):
> name = models.CharField(...)
> """
>
> In admin.py, would be great if it could be done simply like this:
> """
> class BookAdmin(admin.ModelAdmin):
> search_fields = ['title', 'authors']
> admin.site.register(models.Book, BookAdmin)
> """
>
> Then, in the search box of the Book page, I could just type an author and
> search through the m2m field 'authors'. But, doing this way, I got the
> following error:
>
> Related Field has invalid lookup: icontains
>
> I could achieve this search going to the link
> http://localhost/admin/bookstore/book/?authors__name=john , so I still
> think this is possible.
>
You are including the __name in your manual search but you left it out of
the search_fields you listed in your ModelAdmin. So what happens if you
make search_fields = ['title', 'authors__name']?
Karen
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---