W jaki sposób tworzysz abstrakcyjną klasę SearchIndex, podobną do tego, w jaki sposób Django pozwala tworzyć abstrakcyjne modele podstawowe?Jak utworzyć abstrakcyjną klasę Haystack SearchIndex
Mam kilka SearchIndexes, które chciałbym podać te same podstawowe pola (object_id, znacznik czasu, znaczenie, itp.). Obecnie duplikuję cały ten kod, więc próbuję utworzyć "BaseIndex" i po prostu wszystkie prawdziwe klasy indeksu dziedziczą z tego.
ja próbowałem:
class BaseIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
object_id = indexes.IntegerField()
timestamp = indexes.DateTimeField()
class Meta:
abstract = True
class PersonIndex(BaseIndex):
...other fields...
ale to daje mi błąd:
NotImplementedError: You must provide a 'model' method for the '<myapp.search_indexes.BaseIndex object at 0x18a7328>' index.
więc potem próbowałem:
class BaseIndex(object):
text = indexes.CharField(document=True, use_template=True)
object_id = indexes.IntegerField()
timestamp = indexes.DateTimeField()
class PersonIndex(BaseIndex, indexes.SearchIndex, indexes.Indexable):
first_name = indexes.CharField()
middle_name = indexes.CharField()
last_name = indexes.CharField()
ale to daje mi błąd:
SearchFieldError: The index 'PersonIndex' must have one (and only one) SearchField with document=True.
Jak dziedziczę z niestandardowej podklasy SearchIndex?
A [indeksów wyszukiwania 'Meta' klasa] (http://django-haystack.readthedocs.org/en/latest/searchindex_api.html#modelsearchindex) nie ma atrybutu' abstract' ... Nie wiesz skąd to masz? –