﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10516	Admin search doesn't work when having multiple search_fields to the same base model.	Anssi Kääriäinen	Zain Memon	"Searching in admin site does not work when search_fields has multiple elements from the same base class. This is best described by an example:

admin.py:
{{{
from testi.searchTest.models import *
from django.contrib import admin
class TitleInline(admin.TabularInline):
  model = TitleTranslation
  extra = 2

class RecommenderAdmin(admin.ModelAdmin):
  inlines = [TitleInline]

class RecommendationAdmin(admin.ModelAdmin):
  inlines = [TitleInline]
  # This works
  search_fields = ('recommender__titletranslation__text', )
  # But this doesn't
  # search_fields = ('titletranslation__text', 'recommender__titletranslation__text',)

admin.site.register(Recommendation, RecommendationAdmin)
admin.site.register(Recommender, RecommenderAdmin)
}}}


models.py:
{{{
from django.db import models

class Title(models.Model):
  def __unicode__(self):
    try:
      return self.titletranslation_set.filter(lang=""FI"")[0].text
    except:
      return ""No finnish name defined!""

LANG_CHOICES = (('FI', 'Finnish'), ('EN', 'English'),)

class TitleTranslation(models.Model):
  title = models.ForeignKey(Title)
  text = models.CharField(max_length = 100)
  lang = models.CharField(max_length = 2, choices = LANG_CHOICES)

class Recommender(Title):
  pass 

class Recommendation(Title):
  recommender = models.ForeignKey(Recommender)
}}}

Assume we have saved a recommendation with a title of 'Foo' and a recommender with a title of 'Bar'. The foreign key is set from 'Foo' to 'Bar'.

In the example above, when searching for 'ar' nothing is found when using the second version of search_fields. When using the first version, The 'Foo' recommendation is found correctly. In the second version, searching works correctly through titletranslation__text.

"		closed	contrib.admin	1.0		fixed	search, inheritance, admin		Ready for checkin	1	0	0	0	0	0
