Clone wiki

django-lightsearch / Install


First, you need to get the latest version (it's recommended, especially for a new user, because the trunk version may be broken). You can download the version 0.2 with the link below:

Download version 0.2

Once you have downloaded the source archive, extract it. Then, copy the lightsearch folder into your project path.

Set it up

Edit your file and add lightsearch to the INSTALLED_APPS list. Now, you have to define which models have to be included in the search queries. Stay in your file and add the LIGHTSEARCH_MODELS setting. This setting is a list of tuples. Each tuple represents a model. Its first part is its verbose name (ie: the human readable name) and the second is the link to the model (ie: something link <application_name>.<model>). Here is an example:

    # ('Verbose name', '<appname>.<model>'),
    ('Ticket', 'myapp.ticket'),
    ('Author', ''),

It's okay for the file, except if you want to specify which method to use to send search forms (lightsearch uses POST by default). If you want so, add this line to your

LIGHTSEARCH_METHOD = 'post' # Must be 'post' or 'get' 

Right. Now, you have to set which fields of your models have to be included in the search queries. To do so, go in your file(s), and add in your models a Lightsearch class containing a fields list. Here is an example:

class Author(models.Model):
        An author who write a lot of tickets
        >>> jack = Author.objects.create(name="jack", address="", bio="I love Django")
    name = models.CharField('Name', max_length=200)
    address = models.CharField('Address', max_length=200)
    bio = models.TextField('Life')
    def __unicode__(self):
        return '%s (%s)' % (, self.address)
    class Lightsearch:
        fields = ['name', 'bio']

Next, you have to add the templates directory of Lightsearch in your Here is an example:

# Those two lines are needed
import os
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))

# A part of your there

    os.path.join(ROOT_PATH, 'templates'), # This line doesn't matter. Just for example
    os.path.join(ROOT_PATH, 'lightsearch', 'templates'), # Add this line

# The end of your

Finally, you have to add one line in your to indicate where the search queries must be send:

(r'^search/', include('lightsearch.urls')),

That's it. Now you can read the next part of the guide: using Lightsearch.