आप कैसे एक अमूर्त खोज इंडेक्स क्लास बनाते हैं, इसी तरह Django आपको अमूर्त आधार मॉडल कैसे देता है?एक अमूर्त Haystack SearchIndex क्लास बनाने के लिए कैसे करें
मेरे पास कई खोज इंडेक्स हैं जो मैं एक ही मूल फ़ील्ड (object_id, timestamp, महत्व, आदि) देना चाहता हूं। वर्तमान में, मैं इस कोड को डुप्लिकेट कर रहा हूं, इसलिए मैं "बेसइंडेक्स" बनाने की कोशिश कर रहा हूं और बस सभी वास्तविक इंडेक्स क्लास इस से प्राप्त होते हैं।
मैंने कोशिश कर रहा हूँ:
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...
लेकिन यह मुझे त्रुटि देता है:
NotImplementedError: You must provide a 'model' method for the '<myapp.search_indexes.BaseIndex object at 0x18a7328>' index.
तो मैं तो कोशिश की:
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()
लेकिन इन मुझे त्रुटि देता है:
SearchFieldError: The index 'PersonIndex' must have one (and only one) SearchField with document=True.
मैं एक कस्टम खोज इंडेक्स उपclass से कैसे प्राप्त करूं?
एक [खोज अनुक्रमणिका 'Meta' वर्ग] (http://django-haystack.readthedocs.org/en/latest/searchindex_api.html#modelsearchindex) एक विशेषता नहीं है' abstract' ... पता नहीं तुम कहाँ से मिला? –