views:

268

answers:

1

Can someone show me an example of how to filter fulltext search results with django-haystack using attributes? I went through the tutorial on their website but am still mot sure on how to use haystack.

For instance, let's say I have a class Product:

class Product(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField()
    category = models.CharField(max_length=10)
    color = models.CharField(max_length=10)

If I want to provide fulltext search on title & description, and filtering (based on drop-down lists, not free text) on category and color - what do I need to do? Can I use the forms and views that come with haystack?

Thanks.

+4  A: 

Have you looked at the faceting tutorial/documentation on the django-haystack website? It walks you through an example of filtering based on author of the Note model introduced in the getting started tutorial.

Another option separate from haystack and searching is django-filter by Alex Gaynor, it allows you to filter fields based on the contents of the model and not on an index. Therefore it can be used on models that aren't indexed with django-haystack. You can check out the repository here. There are good docs in the doc folder and the included tests show off all the functionality.

Rigsby