The admin search isn't searching the ModelAdmin or Inline files, it's
searching the fields from the model.
You can search a ForeignKey's fields by listing
'foreignkeyfieldname__relatedmodelfieldname' in your search_fields.
So for example if you had the following models:
class Author(models.Model):
...
lastname = models.CharField(max_length=50)
class Book(models.Model):
...
title = models.CharField(max_length=50)
author = models.ForeignKey(Author, related_name='works')
Then you could do the following in your admin:
class BookAdmin(admin.ModelAdmin):
model = Book
search_fields = ['title', 'author__lastname', ...]
However, I'm not sure you can do the reverse:
class AuthorAdmin(admin.ModelAdmin):
model = Author
search_fields = ['lastname', 'works__title']
On Aug 20, 4:45 pm, gondor <
condor.c...@gmail.com> wrote:
> Hello All,
>
> I'm wanting to add a field from my stackedinline form to my
> search_fields in admin. Does anyone know how to do that or point me
> in a general direction/sample code?
>
> Thanx
> Condor