ModelAdmin.get_search_results(request,queryset,search_term) Django 1.6中的新功能。
由于某些原因,与django 1.5兼容
如何在django 1.5
中执行此操作class PersonAdmin(admin.ModelAdmin):
list_display = ('name', 'age')
search_fields = ('name',)
def get_search_results(self, request, queryset, search_term):
# search_term is what you input in admin site, queryset is search results
queryset, use_distinct = super(PersonAdmin, self).get_search_results(request, queryset, search_term)
try:
search_term_as_int = int(search_term)
queryset |= self.model.objects.filter(age=search_term_as_int)
except:
pass
return queryset, use_distinct
答案 0 :(得分:1)