To install django-watson, follow these steps:
src/watsondirectory into your
If you're using south in your project, then it's even easier! Just follow steps 1 and 2, then run
manage.py migrate watson to complete your installation.
Existing website data: If you're integrating django-watson with an existing site, then you'll also want to run
./manage.py buildwatson to index your existing data.
If you want to use django-watson to search your models, then you first need to tell it which models to include in it's indexes. To do this, simply call
watson.register() for each of the models you want to index. A good place to do this is in your application's AppConfig:
from django.apps import AppConfig import watson class YourAppConfig(AppConfig): name = "your_app" def ready(self): YourModel = self.get_model("YourModel") watson.register(YourModel)
Note: In Django 1.6 and earlier, you'll need to place your
register calls in your models.py file:
import watson watson.register(YourModel)
Once you've registered your models with django-watson, run the command
manage.py buildwatson to register any existing models in your database. From now on, any additions, creations or deletions you make will automatically applied, so this command only needs to be run whenever you add a new model to django-watson.
For more information about registering models with django-watson, please visit the registering models wiki page.
You can search for any registered models using the
search_results = watson.search("Your search text") for result in search_results: print result.title, result.url
For more information about searching for models with django-watson, please visit the searching models wiki page.