In the docs at http://www.djangoproject.com/documentation/0.96/model-api/
about search_fields, it says you can use 'the lookup API “follow” notation' to get a foreign key into your search_fields.
Like this:
class FilmClip(models.Model):
...
class Admin:
...
search_fields = (...
'filmcliplog__description' # This is the
line that causes problems
)
class FilmClipLog(models.Model):
clip = models.ForeignKey(FilmClip,
edit_inline=models.TABULAR,
num_in_admin=3)
description = ...
There are two problems with the resulting behavior:
1) Any matching FilmClip that has at least one FilmClipLog will show
up in the results twice.
2) Any matching FilmClip that has no FilmClipLogs will not show up at
all.
From the mysql query log, I've found that the query looks like:
{{{
SELECT ... FROM `filmy_filmclip` INNER JOIN `filmy_filmcliplog` ...
}}}
I think the correct query would be:
{{{
SELECT DISTINCT ... FROM `filmy_filmclip` LEFT OUTER JOIN
`filmy_filmcliplog` ...
}}}
Originally discussed at http://groups.google.com/group/django-users/browse_thread/thread/da44ae1542436d18
(no replies)