title: Using Django Admin search engine in my own views
body: <p>I am trying to use the same search engine as Django uses in the admin page to show results in my custom views. </p>
  
  <p>I found <a href="http://contrib.exoweb.net/browser/exoblog/trunk/blog/utils.py" rel="nofollow">this website</a> that recommends to use the following code:</p>
  
  <pre><code>from django.db.models import Q
  from django.db.models.query import QuerySet
  import operator
  
  def django_admin_keyword_search(model, keywords, base_qs=None):
      """Search according to fields defined in Admin's search_fields"""
      if not keywords: 
          return []
      fields = model._meta.admin.search_fields
  
      qs = QuerySet(model)
  
      for keyword in keywords:
          or_queries = [Q(**{'%s__icontains' % field: keyword}) for field in fields]
          if base_qs is None:
              other_qs = QuerySet(model)
          else:
              other_qs = base_qs
          if qs._select_related:
              other_qs = other_qs.select_related()
          other_qs = other_qs.filter(reduce(operator.or_, or_queries))
          qs = qs &amp; other_qs
  
      return qs
  
  def do_keyword_search(model, query, base_qs=None):
      return django_admin_keyword_search(model, query.split(' '),
                                         base_qs=base_qs)
  </code></pre>
  
  <p>but i am not being able to run that without getting an <strong>Attribute Error ('Options' object has no attribute 'admin')</strong> at this piece of code: <code>fields = model._meta.admin.search_fields</code></p>
  
  <p><strong>EDIT:</strong>
  What am I doing wrong on using the admin default search engine?</p>
  
  <p>Is that any other way to use the default admin search engine?</p>