File: search_indexes.py

package info (click to toggle)
django-haystack 3.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,504 kB
  • sloc: python: 23,475; xml: 1,708; sh: 74; makefile: 71
file content (20 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from haystack import indexes

from .models import Checkin


class CheckinSearchIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    username = indexes.CharField(model_attr="username")
    comment = indexes.CharField(model_attr="comment")
    # Again, if you were using GeoDjango, this could be just:
    #   location = indexes.LocationField(model_attr='location')
    location = indexes.LocationField(model_attr="get_location")
    created = indexes.DateTimeField(model_attr="created")

    def get_model(self):
        return Checkin

    def prepare_text(self, obj):
        # Because I don't feel like creating a template just for this.
        return "\n".join([obj.comment, obj.username])