2👍
✅
I see you’re not subclassing the AldrynIndexBase
or AbstractIndex
base indexes from aldryn-search
, this means you’ll need to define the url field since you’re subclassing haystack’s builtin index class which does not come with any fields predefined.
You can easily add it like so:
class EventIndex(indexes.SearchIndex, indexes.Indexable):
url = indexes.CharField(model_attr='get_absolute_url')
Or:
class EventIndex(indexes.SearchIndex, indexes.Indexable):
url = indexes.CharField()
def prepare_url(self, obj):
return obj.get_absolute_url()
I recommend approach number two because approach number one behaves differently if the provided attribute string has double underscores like get__title woul look for event.get.title instead of event.get__title.
If your Event
model supports multiple languages using libraries like django-hvad or django-parler, I highly recommend you use AldrynIndexBaseor
AbstractIndexinstead of haystack's
indexes.SearchIndex“`.
Source:stackexchange.com