Haystack
  • Welcome to Haystack!
    • Getting Started
    • Advanced Uses
    • Reference
    • Developing
    • Requirements
  • Getting Started with Haystack
    • Installation
    • Configuration
    • Handling Data
    • Setting Up The Views
    • Complete!
    • What’s Next?
  • Glossary
  • Views & Forms
    • Forms
    • Views
  • Template Tags
    • highlight
    • more_like_this
  • Management Commands
    • clear_index
    • update_index
    • rebuild_index
    • build_solr_schema
    • haystack_info
  • Architecture Overview
    • SearchQuerySet
    • SearchQuery
    • SearchBackend
    • SearchSite
    • SearchIndex
  • Backend Support
    • Supported Backends
    • Backend Capabilities
    • Backend Support Matrix
    • Wishlist
  • Installing Search Engines
    • Solr
    • Elasticsearch
    • Whoosh
    • Xapian
  • Haystack Settings
    • HAYSTACK_DEFAULT_OPERATOR
    • HAYSTACK_CONNECTIONS
    • HAYSTACK_ROUTERS
    • HAYSTACK_SIGNAL_PROCESSOR
    • HAYSTACK_DOCUMENT_FIELD
    • HAYSTACK_SEARCH_RESULTS_PER_PAGE
    • HAYSTACK_CUSTOM_HIGHLIGHTER
    • HAYSTACK_ITERATOR_LOAD_PER_QUERY
    • HAYSTACK_LIMIT_TO_REGISTERED_MODELS
    • HAYSTACK_ID_FIELD
    • HAYSTACK_DJANGO_CT_FIELD
    • HAYSTACK_DJANGO_ID_FIELD
    • HAYSTACK_IDENTIFIER_METHOD
  • (In)Frequently Asked Questions
    • What is Haystack?
    • Why should I consider using Haystack?
    • When should I not be using Haystack?
    • Why was Haystack created when there are so many other search options?
    • What’s the history behind Haystack?
    • Why doesn’t <search engine X> have a backend included in Haystack?
  • Sites Using Haystack
    • LJWorld/Lawrence.com/KUSports
    • AltWeeklies
    • Trapeze
    • Vickerey.com
    • Eldarion
    • Sunlight Labs
    • NASA
    • AllForLocal
    • HUGE
    • Brick Design
    • Winding Road
    • Reddit
    • Pegasus News
    • Rampframe
    • Forkinit
    • Structured Abstraction
    • CustomMade
    • University of the Andes, Dept. of Political Science
    • Christchurch Art Gallery
    • DevCheatSheet.com
    • TodasLasRecetas
    • AstroBin
    • European Paper Company
    • mtn-op
    • Crate
    • Pix Populi
    • LocalWiki
    • Pitchup
    • Gidsy
    • GroundCity
    • Docket Alarm
    • Educreations
  • Haystack-Related Applications
    • Sub Apps
    • Haystack-Enabled Apps
  • Debugging Haystack
    • “No module named haystack.”
    • “No results found.” (On the web page)
    • “LockError: [Errno 17] File exists: ‘/path/to/whoosh_index/_MAIN_LOCK’”
    • “Failed to add documents to Solr: [Reason: None]”
    • “Got an unexpected keyword argument ‘boost’”
  • Migrating From Haystack 1.X to Haystack 2.X
    • Settings
    • Backends
    • Indexes
    • Removal of RealTimeSearchIndex
    • Done!
    • Advanced Uses
  • Python 3 Support
    • Supported Backends
    • Partially Supported Backends
    • Notes
  • Contributing
    • Philosophy
    • Guidelines For Reporting An Issue/Feature
    • Guidelines For Contributing Code
    • Guidelines For Core Contributors
  • Best Practices
    • Good Search Needs Good Content
    • Avoid Hitting The Database
    • Content-Type Specific Templates
    • Real-Time Search
    • Use Of A Queue For A Better User Experience
  • Highlighting
    • Highlighter
  • Faceting
    • What Is Faceting?
    • 1. Determine Facets And SearchQuerySet
    • 2. Switch to the FacetedSearchView and FacetedSearchForm
    • 3. Display The Facets In The Template
    • 4. Narrowing The Search
  • Autocomplete
    • Step 1. Setup The Data
    • Step 2. Performing The Query
    • Example Implementation
  • Boost
    • Term Boost
    • Document Boost
    • Field Boost
  • Signal Processors
    • Default - BaseSignalProcessor
    • Realtime - RealtimeSignalProcessor
    • Custom SignalProcessors
  • Multiple Indexes
    • Specifying Available Connections
    • Management Commands
    • Automatic Routing
    • Manually Selecting
    • Custom Index Selection
  • Rich Content Extraction
    • Extracting Content
    • Indexing Extracted Content
  • Spatial Search
    • Additional Requirements
    • Support
    • Geospatial Assumptions
    • Indexing
    • Querying
    • Ordering
    • Caveats
  • SearchQuerySet API
    • Why Follow QuerySet?
    • Quick Start
    • SearchQuerySet
    • The content Shortcut
    • SearchQuerySet Methods
    • EmptySearchQuerySet
    • RelatedSearchQuerySet
  • SearchIndex API
    • Quick Start
    • Background
    • Keeping The Index Fresh
    • Advanced Data Preparation
    • Adding New Fields
    • Search Index
    • ModelSearchIndex
  • Input Types
    • Available Input Types
    • Creating Your Own Input Types
  • SearchField API
    • Subclasses
    • Usage
    • Field Options
    • Method Reference
  • SearchResult API
    • Attribute Reference
    • Method Reference
  • SearchQuery API
    • SQ Objects
    • Backend-Specific Methods
    • Inheritable Methods
  • SearchBackend API
    • Method Reference
  • Running Tests
    • Everything
    • Cherry-Picked
    • Configuring Solr
    • Configuring Elasticsearch
  • Creating New Backends
    • SearchBackend
    • SearchQuery
  • Utilities
    • get_identifier
 
Haystack
  • Docs »
  • Welcome to Haystack! »
  • Django Admin Search
  • Edit on GitHub

Django Admin SearchΒΆ

Haystack comes with a base class to support searching via Haystack in the Django admin. To use Haystack to search, inherit from haystack.admin.SearchModelAdmin instead of django.contrib.admin.ModelAdmin.

For example:

from haystack.admin import SearchModelAdmin
from .models import MockModel


class MockModelAdmin(SearchModelAdmin):
    haystack_connection = 'solr'
    date_hierarchy = 'pub_date'
    list_display = ('author', 'pub_date')


admin.site.register(MockModel, MockModelAdmin)

You can also specify the Haystack connection used by the search with the haystack_connection property on the model admin class. If not specified, the default connection will be used.

If you already have a base model admin class you use, there is also a mixin you can use instead:

from django.contrib import admin
from haystack.admin import SearchModelAdminMixin
from .models import MockModel


class MyCustomModelAdmin(admin.ModelAdmin):
    pass


class MockModelAdmin(SearchModelAdminMixin, MyCustomModelAdmin):
    haystack_connection = 'solr'
    date_hierarchy = 'pub_date'
    list_display = ('author', 'pub_date')


admin.site.register(MockModel, MockModelAdmin)
Next Previous

© Copyright 2009-2013, Daniel Lindsley.

Built with Sphinx using a theme provided by Read the Docs.