有没有办法让django管理员搜索多个术语,可以用逗号分隔?

时间:2015-03-25 01:47:27

标签: django python-2.7 django-admin

我有这段代码,但老老实实地选择性地工作:

  def get_search_results(self, request, queryset, search_term):
        queryset, use_distinct = super(Name_of_adminclass, self).get_search_results(
                                           request, queryset, search_term)
        search_words = search_term.split(',')

        if search_words:
            q_objects = [Q(**{field + '__iexact': word})
                            for field in self.search_fields
                            for word in search_words]
            queryset |= self.model.objects.filter(reduce(or_, q_objects))
        return queryset, use_distinct 

同样出于任何原因,它似乎禁用过滤器以使它们不起作用,用逗号搜索确切的术语有时会起作用,任何人都可以提供帮助吗?

0 个答案:

没有答案